问题
When I try to compile a test console application to test some functionality on a static library on the same workspace, i run into problems in the linking stage of the binary, it only happen when I choose to use libc++ standard library.
The missing symbols error is the follow :
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::empty() const", referenced from:
libtorrent::torrent::replace_trackers(std::__1::vector<libtorrent::announce_entry, std::__1::allocator<libtorrent::announce_entry> > const&) in libLibOFFTorrent-xcode.a(torrent.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I choose stdlibc++ in both targets everything compiles ok and it runs OK.
my questions are :
- there are some restriction on using libc++ on static libraries?
- its a bug in apple/clang++ linker tool?
- how can I configure the project to use libc++ with my static libraries?
- why the linker tool does not find the symbols of a standard c++ libraries on a static lib?, (any other lib that depends on is compiled against libc++)
- should I forget the idea on using libc++?
notes:
- the static library depends on libboost_system, witch i had compiled with libc++ and libstdc++ with the same results
- when i run the test with the 'bjam' tool it runs OK, maybe the jam files chooses libstdc++ to compile the files.
- I know that changing the standard library fix the linking problem , I only want to know why is that.
UPDATE: when I remove the reference to string::empty in the static lib project, the project that depends on compiles with libc++ fine and runs, but it gets in a infinite loop.
UPDATE 2: removing the string::empty references causes no effect when I compile the whole thing with libstdc++ it runs fine. no loops, this makes me think that is a bug or something like that.
UPDATE 3: when it compiles this is the place where the programs loops indefinitely :
回答1:
It seems that one of your dependencies (libtorrent
) has been built against libstdc++
.
Check the namespace : std::__1::basic_string
. It has the __1
prefix, usually indicating libstdc++
).
I may be wrong but I think you need to rebuild your libtorrent
against libc++
if you absolutely want to use this one.
Note that it is pretty common to use the stdlibc++
.
回答2:
Did you by any chance compile libtorrent with a -D_LIBCPP_INLINE_VISIBILITY=""?
The reason I ask is that std::string::empty()
isn't in libc++.dylib because it is marked up with "always_inline". And so it should have been inlined into libtorrent when it was used.
来源:https://stackoverflow.com/questions/14803622/how-i-do-compile-a-application-against-a-static-library-compiled-with-libc-in