我正在运行ubuntu,我可以构建ICU
我包括:
#include <unistr.h>
using namespace icu;
Run Code Online (Sandbox Code Playgroud)
这是我对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
Run Code Online (Sandbox Code Playgroud)
然后我链接到
/usr/local/lib/libicuuc.a
Run Code Online (Sandbox Code Playgroud)
并尝试编译
icu::UnicodeString s1=UNICODE_STRING("such characters are safe 123 %-.", 32);
Run Code Online (Sandbox Code Playgroud)
但得到错误
undefined reference to `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)'
Run Code Online (Sandbox Code Playgroud)
我在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
Run Code Online (Sandbox Code Playgroud)
小智 3
我注意到你的 g++ 行没有指向你所说的安装 icu 的 /usr/local/lib/libicuuc.a 。显然,它是根据标头进行编译的,但是静态库是否存在于您正在使用的路径中(“/home/user/myProject/icu/libicuuc.a”)?