提升静态链接提升区域设置错误

boost static link boost.locale error

本文关键字:设置 错误 链接 静态 区域      更新时间:2023-10-16
#include <boost/locale/encoding.hpp>
int main()
{
    const std::string strutf8("你好,世界");
    std::wstring wtrutf16 = boost::locale::conv::to_utf<wchar_t>(strutf8, "UTF-8");
    return 0;
}

这是我的代码,我想在 CentOS 7 64 位系统上的项目中使用 boost.locale lib,我使用 ./bootstrap 和 ./b2 编译 boost 库,除了静态链接 libboost_locale.a,我在控制台中使用以下命令编译,我工作正常:

g++ -o locale locale.cpp -static -L ~/Downloads/boost_1_57_0/stage/lib -lboost_system -lboost_filesystem -lboost_locale

GCC 显示的错误如下所示:

/root/Downloads/boost_1_57_0/stage/lib/libboost_locale.a(codepage.o):in fuction ‘boost::locale::conv::impl::uconv_to_utf<wchar_t>::open(char const*, boost::locale::conv::method_type)’:
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0xb0):undefined reference to ‘ucnv_open_50’未定义的引用
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0xcd):undefined reference to ‘ucnv_close_50’未定义的引用
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x146):undefined reference to ‘UCNV_FROM_U_CALLBACK_STOP_50’
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x14e):undefined reference to ‘ucnv_setFromUCallBack_50’
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x16b):undefined reference to ‘UCNV_TO_U_CALLBACK_STOP_50’
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x17b):undefined reference to ‘ucnv_setToUCallBack_50’
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x18f):undefined reference to ‘ucnv_getMaxCharSize_50’
codepage.cpp:(.text._ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE[_ZN5boost6locale4conv4impl12uconv_to_utfIwE4openEPKcNS1_11method_typeE]+0x1a2):undefined reference to ‘ucnv_close_50’
                          ....

我不知道发生了什么,我尝试安装 libiconv.a,但我没有工作。所以,Anynoe会告诉我如何解决这个问题吗?

"undefined reference"后面的符号名称属于 ICU4C。看起来您在编译加速区域设置时选择使用 ICU4C。

有两种解决方案:

  1. 添加链接ICU4C库的参数,请访问如何使用ICU了解更多详情。
  2. 重建 Boost Locale,设置 boost.locale.icu=off