gpt4 book ai didi

c++ - 对 `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)' 的 undefined reference

转载 作者:IT王子 更新时间:2023-10-29 00:21:07 36 4
gpt4 key购买 nike

我正在运行 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

最佳答案

当你运行时:

./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>在任何事情之前,例如

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 进行编译和链接.

如果您愿意,可以确保样板 header 像 unicode/uconfig.hunicode/platform.h之前由编译器自动包含通过使用预包含 header 的任何其他内容,例如

icu_preinc.h

// pre-include header for icu
#include <unicode/uconfig.h>
#include <unicode/platform.h>

你通过选项传递给 GCC 或 clang:

-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

关于c++ - 对 `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35246695/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com