4

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)

error in xcode missing symbols on a static library

When I choose stdlibc++ in both targets everything compiles ok and it runs OK.

standar library options (xcode)

my questions are :

  1. there are some restriction on using libc++ on static libraries?
  2. its a bug in apple/clang++ linker tool?
  3. how can I configure the project to use libc++ with my static libraries?
  4. 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++)
  5. should I forget the idea on using libc++?

notes:

  1. the static library depends on libboost_system, witch i had compiled with libc++ and libstdc++ with the same results
  2. when i run the test with the 'bjam' tool it runs OK, maybe the jam files chooses libstdc++ to compile the files.
  3. 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 : enter image description here

alter
  • 333
  • 4
  • 14

2 Answers2

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++.

bquenin
  • 1,470
  • 2
  • 12
  • 12
  • libtorrent IS the static library that I set up in my workspace in xcode, it is compiled with libc++ (the screenshot is from the setting of libtorrent) , everything is fine when i compile it with libstdc++, i had rebuild the lib a lot of times. this is very weird. ill try to remove the call to string::empty() to see what happens. – alter Feb 11 '13 at 01:01
0

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.

Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577
  • no, when compiling it with that flag I got a lot of unresolved symbols errors. All related with strings, using libstdc++ for the moment. – alter Feb 11 '13 at 12:50
  • Ok, I don't suggest that you use that flag. Indeed I suggest you do not. Btw, the `std::__1` symbols come from libc++, not libstdc++. – Howard Hinnant Feb 11 '13 at 15:11
  • I notice that, I had made that test early, i know std::__1 is from libc++ that is why is very weird. as i said in my update on the question, i was able to compile and run the tests, but it hangs on some methods in the vector class., Im not looking forward in this issue but ill be glad to know why this happens. – alter Feb 11 '13 at 16:35
  • Using the command line tool nm on each of your compiled libraries, can you find any reference to __ZNSsD1Ev? This is ~string() from libstdc++. Finding it would indicate that object has been compiled with libstdc++ instead of libc++. – Howard Hinnant Feb 11 '13 at 17:36
  • 1
    A shot in the dark: try adding the following to C++ Other Flags: -D'_LIBCPP_EXTERN_TEMPLATE(...)=' – Howard Hinnant Feb 11 '13 at 18:00
  • it compiles with the reference to string::empty but the program gets into an infinite loop, when i pause the execution this is the stack trace (see screenshot) – alter Feb 11 '13 at 18:14
  • I can't see which members of __vector_base are being called in the screen shot. Any luck with the nm search for __ZNSsD1Ev? If found, that could explain the crash. – Howard Hinnant Feb 11 '13 at 18:23
  • theres no reference on any of the libraries to that symbol. (boost is compiled against libc++ too) – alter Feb 11 '13 at 18:33