How do I compile an application against a static library compiled with libc ++ in xcode / clang / macos?

When I try to compile a test console application to test some functionality in a static library in the same workspace, I run into problems in the linking step of the binary, this only happens when I choose to use the libc ++ standard library.

The missing characters error is as follows:

    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 select stdlibc ++ for both purposes, everything compiles fine and it works fine.

standar library options (xcode)

my questions:

  • Are there some restrictions on using libc ++ in static libraries?
  • its a bug in apple / clang ++ linker tool?
  • how can i configure a project to use libc ++ with my static library?
  • why doesn't the linker tool find the standard C ++ library symbols on the static lib ?, (any other lib that depends on is compiled to libc ++)
  • Should I forget the idea of ​​using libc ++?

notes:

  • the static library depends on libboost_system, because I compiled with libc ++ and libstdc ++ with the same results
  • When I run the test with the "bjam" tool it works fine, maybe the jam files are picking libstdc ++ to compile the files.
  • I know that changing the standard library fixes the linking issue, I just want to know why.

UPDATE : When I remove the line reference :: is empty in a static lib project, the project that depends on compiling with libc ++ works fine, but it ends up in an infinite loop.

UPDATE 2 : Removing the line :: empty references has no effect when compiling all content with libstdc ++. no loops, it makes me think it is a bug or something.

UPDATE 3 : On compilation, this is where programs loop endlessly:enter image description here

+3


source to share


2 answers


It seems like one of your dependencies ( libtorrent

) was built against libstdc++

.

Check the namespace: std::__1::basic_string

. It has a prefix __1

usually indicating libstdc++

).



I may be wrong, but I think you need to rebuild yours libtorrent

against libc++

if you absolutely want to use this one.

Please note that it is used quite often stdlibc++

.

+1


source


Did you accidentally compile libtorrent with -D_LIBCPP_INLINE_VISIBILITY = ""?



I am asking what is std::string::empty()

not in libc ++. dylib because it is marked "always_inline". And so it had to be built into libtorrent when it was used.

0


source







All Articles