【发布时间】:2014-07-26 01:34:15
【问题描述】:
我在尝试在 C++ 中添加对 boost 模块的引用时遇到了这个奇怪的问题。首先,你需要知道我在玩一点 C++,所以也许这是我错过的一个超级简单的菜鸟。
这是我的环境,因此您可以获得更多背景信息:Mac OS Mavericks,带有 boost 1.55 和 g++-mp-4.8 的 MacPorts 端口。我目前正在链接和使用boost_system-mt 和boost_filesystem-mt。
问题是我正在从事一个正在进行的项目,它一直在使用 boost 并且编译良好。我正在尝试将utf8 字符串转换为Latin1,因此我包含boost/locale.hpp,并将-lboost_locale-mt 添加到链接器参数中。对于我正在做的任务:
boost::locale::conv::from_utf<char>(value, "Latin1")
到目前为止一切顺利,编译正常,但是当链接应该完成时,我收到以下错误:
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> > boost::locale::conv::from_utf<char>(char const*, char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)", referenced from:
clsByteQueue::WriteUnicodeStringFixed(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in clsByteQueue.o
clsByteQueue::WriteUnicodeString(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in clsByteQueue.o
ld: symbol(s) not found for architecture x86_64
链接器正在使用以下命令运行:
g++-mp-4.8 -fstack-protector -ggdb -o "bin/foobar" <all compiled.o files goes here> -L/opt/local/lib/ -levent -levent_core -levent_extra -lboost_system-mt -lboost_filesystem-mt -lboost_locale-mt
问题是,我检查了/opt/local/lib/libboost_locale-mt.a 不仅存在,而且还针对正确的架构进行了编译:
$ lipo -info /opt/local/lib/libboost_locale-mt.a
input file /opt/local/lib/libboost_locale-mt.a is not a fat file
Non-fat file: /opt/local/lib/libboost_locale-mt.a is architecture: x86_64
另外,我在文件中搜索了 from_utf 并且出现了以下符号:
$ otool -tv /opt/local/lib/libboost_locale-mt.a | grep from_utf
__ZN5boost6locale4conv8from_utfIcEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPKT_SC_RKS9_NS1_11method_typeE:
使用c++filt 解开它后,我可以验证它与链接器未找到的符号相同(除非 __1 意味着什么?):
$ c++filt __ZN5boost6locale4conv8from_utfIcEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPKT_SC_RKS9_NS1_11method_typeE
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::locale::conv::from_utf<char>(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::locale::conv::method_type)
所以,我现在几乎一无所知。
你们能帮我找出问题所在,或者至少我还能尝试什么吗?
提前致谢。
【问题讨论】:
-
__1确实意味着什么。这意味着它来自 clang 的 libc++,而不是 g++ 使用的 libstdc++。
标签: c++ macos boost linker g++