Gonzalo Larralde
Gonzalo Larralde

Reputation: 3541

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

I'm having this weird issue trying to add a reference to a boost module in C++. First of all, you need to know that I'm playing a little with C++, so maybe it's a super easy-rookie thing that I have missed.

This is my environment, so you get more context: Mac OS Mavericks, with the MacPorts port of boost 1.55 and g++-mp-4.8. I'm currently linking and using boost_system-mt and boost_filesystem-mt.

The thing is I'm working in an ongoing project, and it's using boost all along and compiling fine. I'm trying to convert an utf8 string to Latin1, so I included boost/locale.hpp, and added -lboost_locale-mt to the linker params. For the task I'm doing:

boost::locale::conv::from_utf<char>(value, "Latin1")

So far so good, it compiles fine, but then when the linking should be done, I get the following error:

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

The linker is running with the following command:

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

The thing is, I checked and /opt/local/lib/libboost_locale-mt.a not only exists but also is compiled for the proper architecture:

$ 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

Also, I made a search in the file for from_utf and the following symbol appeared:

$ otool -tv /opt/local/lib/libboost_locale-mt.a | grep from_utf
__ZN5boost6locale4conv8from_utfIcEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPKT_SC_RKS9_NS1_11method_typeE:

After unmangling it using c++filt I could verify that is the same symbol that the linker is not finding (unless that __1 means something?):

$ 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)

So, I'm pretty much clueless by now.

Can you guys help me to find out what is wrong, or at least what else may I try?

Thanks in advance.

Upvotes: 1

Views: 314

Answers (1)

T.C.
T.C.

Reputation: 137301

Looks like your boost::locale was compiled with clang and libc++, which is the default compiler and standard library on Mac OS X, while your program was compiled with g++ and libstdc++, which is g++'s standard library. The two standard libraries are not binary compatible.

You need to either compile everything with clang and libc++, or get a version of boost that's compiled with g++ and libstdc++.

Upvotes: 2

Related Questions