提升静态链接boost.locale错误

时间:2015-04-11 10:08:44

标签: c++ boost linker locale

#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;
}

这是我的代码,我想在我的项目中使用boost.locale lib在centos 7 64位系统上,我使用./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会告诉我如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

&#34;未定义参考&#34;之后的符号名称属于ICU4C。 看起来您在编译Boost Locale时选择使用ICU4C。

有两种解决方案:

  1. 添加用于关联ICU4C库的参数,请访问How To Use ICU了解详情。
  2. 重建Boost Locale,设置boost.locale.icu = off