5

I am building a shared lib by linking a bunch of code with a static lib (.a) on Linux in C++. I have a method defined in a static library. When I use nm -C to print the symbol in that static library is appears as:

 Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::string const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&)

The symbol is not defined in the output .so file (the library I am building), but when I list the undefined symbols using nm -uC it prints:

Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&)

The difference being one the first use std::string const& and the second uses std::__1::basic_string, std::__1::allocator > const&

I'm trying to understand why it is not finding the symbol. Shouldn't the two match up since they are essentially the same?

For context, I am attempting to compile an Alembic Importer which come with Unreal Editor 4 for linux. The library I am attempting to link in is the alembic library.

Luke
  • 51
  • 1
  • 3
  • Your question is unclear. What does "I am linking a static lib (.a) into a shared lib (.so) on Linux" mean. Are you taking an existing .a file and relinking it to a .so file. Are you linking a .a file with an existing .so file. If you're "linking a static lib" file, where did the "output .so file" come from, all of a sudden. You need to make your question more clear. – Sam Varshavchik Feb 19 '17 at 03:57
  • 1
    Can it be something like libstdc++ vs libc++? Like when you build .a you use `-stdlib=libstdc++` and when you build .so it's `-stdlib=libc++` or vice versa? – Paul Feb 19 '17 at 04:02
  • Thanks for responding. I am creating a plugin for Unreal Editor which is a shared lib (the final output .so). That shared library is dependent on a static library. So i am creating a new .so from a bunch of code and an existing .a file. – Luke Feb 19 '17 at 04:03
  • @paul maybe? can you elaborate? – Luke Feb 19 '17 at 04:06
  • 1
    @Paul: Good point. OP should read this: http://stackoverflow.com/questions/8454329/why-cant-clang-with-libc-in-c0x-mode-link-this-boostprogram-options-examp - the __1 is relevant. – John Zwinck Feb 19 '17 at 04:08
  • You have to specify your build commands. – n. m. could be an AI Feb 19 '17 at 04:42
  • @Paul and JohnZwinck Thanks I think that is my problem – Luke Feb 19 '17 at 04:47
  • Also see [undefined std::__1::basic_string clang gcc site:stackoverflow.com](https://www.google.com/search?q=undefined+std%3A%3A__1%3A%3Abasic_string+clang+gcc+site%3Astackoverflow.com). The `__1` is LLVM's anonymous namespace. It usually means you are mixing and matching LLVM's runtime (`libc++`) with GNU's runtime (`libstdc++`). You usually do that by mixing GCC compiler and Clang compiler. – jww Feb 19 '17 at 17:47

1 Answers1

11

You are trying to link code compiled against libc++ (the clang's standard C++ library) and code compiled against libstdc++ (the gcc's standard C++ library). This isn't going to work too well.

Check it against your libraries.

On my system:

> nm -DC /usr/lib64/libc++_shared.so | grep 'std::__1'
  === lots of output ===
> nm -DC /usr/lib64/libc++_shared.so | grep 'std::basic'
  === nothing ===
> nm -DC /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/libstdc++.so.6 | grep 'std::__1'
  === nothing ===
> nm -DC /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/libstdc++.so.6 | grep 'std::basic'
  === lots of output ===

On your system the files may be at different locations but the result shou;d be the same.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243