我正在运行ubuntu,我可以构建ICU
我已经包括:
#include <unistr.h>
using namespace icu;
这是我对ICU的构建方法:
CPPFLAGS="-DU_USING_ICU_NAMESPACE=0"
CPPFLAGS="-DU_CHARSET_IS_UTF8=1"
export CFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_STATIC_IMPLEMENTATION"
export CXXFLAGS="-DU_USING_ICU_NAMESPACE=0 -std=gnu++0x -DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_HAVE_CHAR16_T=1 -DUCHAR_TYPE=char16_t -Wall --std=c++0x -DU_STATIC_IMPLEMENTATION"
export CPPFLAGS="-DU_USING_ICU_NAMESPACE=0 -DU_CHARSET_IS_UTF8=1 -DU_STATIC_IMPLEMENTATION"
export LDFLAGS="-std=gnu++0x"
./runConfigureICU Linux --enable-static --disable-shared --disable-renaming
make check
sudo make install
然后我链接到
/usr/local/lib/libicuuc.a
并尝试编译
icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);
但得到错误
undefined reference to `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)'
我在SO上发现了另一篇关于同样问题的帖子,但是当我按照提供的步骤操作时,它不能解决我的问题,可能是另一个版本。
编辑:这是构建项目时IDE的输出
Cleaning Solution: myProject (Debug)
Cleaning: myProject (Debug)
Removing output files...
Clean complete
Building Solution: myProject (Debug)
Building: myProject (Debug)
Performing main compilation...
Precompiling headers
Compiling source to object files
g++ -MMD "/home/user/myProject/myProject/main.cpp" -g -O0 -std=c++11 -DDEBUG -I"/home/user/myProject/myProject/include" -I"/home/user/myProject/icu/unicode" -I"/home/user/myProject/myProject/.prec/Debug" -c -o "/home/user/myProject/myProject/bin/Debug/main.o"
Generating binary "myProject" from object files
g++ -o "/home/user/myProject/myProject/bin/Debug/myProject" "/home/user/myProject/myProject/bin/Debug/main.o"
"/home/user/myProject/icu/libicuuc.a"
/home/user/myProject/myProject/bin/Debug/main.o: In function `icuTest':
/home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::StringPiece::StringPiece(char const*)'
/home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::fromUTF8(icu_56::StringPiece const&)'
/home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::~UnicodeString()'
/home/user/myProject/myProject/icuTest.hpp:3: undefined reference to `icu_56::UnicodeString::~UnicodeString()'
collect2: error: ld returned 1 exit status
Build complete -- 4 errors, 0 warnings
---------------------- Done ----------------------
Build: 4 errors, 0 warnings
答案 0 :(得分:3)
我注意到你的g ++行没有指向/usr/local/lib/libicuuc.a,你说你安装了icu。它显然正在编译标题OK,但静态库是否存在于您正在使用的路径中(&#34; /home/user/myProject/icu/libicuuc.a")?
答案 1 :(得分:2)
当你跑步时:
./runConfigureICU Linux --enable-static --disable-shared --disable-renaming
你注意到警告了吗?:
*** WARNING: You must set the following flags before code compiled against this ICU will function properly:
-DU_DISABLE_RENAMING=1
The recommended way to do this is to prepend the following lines to source/common/unicode/uconfig.h or #include them near the top of that file.
/* -DU_DISABLE_RENAMING=1 */
#define U_DISABLE_RENAMING 1
如果没有,那么现在就这样做。
接下来,在其他任何事情之前将测试程序修改为#include <unicode/uconfig.h>
,
e.g。
<强>的main.cpp 强>
#include <unicode/uconfig.h>
#include <unicode/platform.h>
#include <unicode/unistr.h>
int main()
{
icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);
(void)s1;
return 0;
}
它将编译并链接到libicuuc.a
。
如果您希望确保像unicode/uconfig.h
这样的样板标题,您可以
并且之前编译器自动包含unicode/platform.h
通过使用预包含标题来做任何其他事情,例如
<强> icu_preinc.h 强>
// pre-include header for icu
#include <unicode/uconfig.h>
#include <unicode/platform.h>
您传递给GCC或使用以下选项进行铿锵:
-include /path/to/icu_preinc.h
如果您使用基于CPPFLAGS
的构建系统,则可以在make
中添加此选项。
对于上面的玩具程序,只需在命令行上定义U_DISABLE_RENAMING=1
即可,而不包括<unicode/uconfig.h>
g++ -DU_DISABLE_RENAMING=1 -o prog main.cpp -L/your/libicuuc/search/path -licuuc
答案 2 :(得分:1)
我认为问题出在g ++语法中:
searchListing(event) {
event.persist();
console.log(event.target.value);
}
您要使用目标文件main.o和目标文件libicuuc.a构建myProject。但是,后者不是目标文件,而是静态库。我认为你应该将g ++行修改为:
g++ -o "/home/user/myProject/myProject/bin/Debug/myProject" "/home/user/myProject/myProject/bin/Debug/main.o" "/home/user/myProject/icu/libicuuc.a"
g++ /home/user/myProject/myProject/bin/Debug/main.o -L/home/user/myProject/icu/ -licuuc -o /home/user/myProject/myProject/bin/Debug/myProject
告诉链接器在/ home / user / myProject / icu /文件夹中查找库,-L/home/user/myProject/icu/
告诉它链接名为libicuuc.a或libicuuc.so的库
答案 3 :(得分:1)
注意:对于ICU 67,应为using namespace icu_67
。