'ld:找不到建筑???符号",即使它在那里

'ld: symbol(s) not found for architecture ???' even when it's there

本文关键字:在那里 符号 ld 找不到 建筑      更新时间:2023-10-16

我有这个奇怪的问题,试图在c++中添加一个boost模块的引用。首先,你需要知道我在玩一点c++,所以也许这是我错过的一个超级简单的新手的东西。

这是我的环境,所以你得到更多的上下文:Mac OS Mavericks,与MacPorts端口的boost 1.55和g++-mp-4.8。我目前正在链接和使用boost_system-mtboost_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)

所以,我现在几乎一无所知。

你们能帮我找出什么是错的,或者至少我可以尝试什么?

看起来你的boost::locale是用clang和libc++编译的,这是Mac OS X的默认编译器和标准库,而你的程序是用g++和libstdc++编译的,这是g++的标准库。这两个标准库不兼容。

你需要用clang和libc++编译所有的东西,或者得到一个用g++和libstdc++编译的boost版本