1

I have been trying to link log4cxx into my ObjC/ObjC++/C++ project. It compiles but always fails at the link stage due to undefined symbols. By turning on the Xcode build option "Display Mangled Names" I was able to see why this is the case. The mangled names that the linker is looking for are different from the mangled names in the log4cxx.dylib file.

For example

"log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const"

becomes

"__ZNK7log4cxx6Logger9forcedLogERKNS_7helpers10ObjectPtrTINS_5LevelEEERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERKNS_3spi12LocationInfoE"

from the linker's point of view. However the closest symbol that nm reports in log4cxx.dylib is

__ZNK7log4cxx6Logger9forcedLogERKNS_7helpers10ObjectPtrTINS_5LevelEEERKSbIwSt11char_traitsIwESaIwEERKNS_3spi12LocationInfoE

I created this library was created using the Xcode project provided by Apache.

I see that a similar question (How can I resolve single symbol link error when dynamically linking XCode project to lib4cxx library?) was asked earlier but there was no useful response.

A resolution would be greatly appreciated.

1 Answer 1

3

You have mismatched C++ standard library settings. Some of the code is using the new libc++, and some is using GNU's libstdc++. Choose the one you want and change the project settings so they're consistent.

You can use the c++filt command line tool to un-mangle C++ symbol names:

% c++filt __ZNK7log4cxx6Logger9forcedLogERKNS_7helpers10ObjectPtrTINS_5LevelEEERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEERKNS_3spi12LocationInfoE
log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const
% c++filt __ZNK7log4cxx6Logger9forcedLogERKNS_7helpers10ObjectPtrTINS_5LevelEEERKSbIwSt11char_traitsIwESaIwEERKNS_3spi12LocationInfoE
log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, log4cxx::spi::LocationInfo const&) const

Note for example std::basic_string (libstdc++) versus std::__1::basic_string (libc++).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I didn't know of these competing libraries.
I have the same issue. When i compile my code with g++ version 4.8 I get the same undefined symbol errors, with g++ version 5.4, however, it works. Due to some technical reasons, i cannot use g__ version 5.4, so I am trying to find a solution for 4.8. When I ran ldd on the object file it has libstdc++ in both cases (4.8 and 5.4). What could be the reason, and how can I resolve this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.