Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the __1 symbol come from when using LLVM's libc++?

I see a fair amount of questions like Apple Mach-O Linker (Id) Error and Undefined symbols in cryptopp at IOS 64-bit project. The problem is usually described as:

Undefined symbols for architecture i386:
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()", referenced from:
      cv::gpu::error(char const*, char const*, int, char const*) in opencv2(gpumat.o)

The problem often reduces to mixing/matching -stdlib=libc++ (LLVM C++ runtime) and -stdlib=libstdc++ (GNU C++ runtime). The LLVM C++ runtime (libc++) has an __1 decoration symbol, but the GNU C++ runtime libstdc++ lacks the __1 symbol in its name. It causes linker problems for symbols that appears to have the same name (like std::string).

Where does the __1 symbol come from when using LLVM's libc++?

Why was the problem not solved with a gnu namespace and an llvm namespace?


Here's a related question: libc++ - stop std renaming to std::__1?. But it kind of misses the point in that a rename does not occur.

like image 506
jww Avatar asked Mar 27 '15 04:03

jww


People also ask

What is STD __1 :: string?

__1 is an inline namespace located in std : namespace std { inline namespace __1 { // string, ... } } The inline means that one does not have to specify that the structure/function/variable is located in that namespace, so that one can simply use std::string instead of std::__1::string .

What linker does clang use?

Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.

Can GCC use libc ++?

Using libc++ with GCCYou must manually configure the compile and link commands. In particular you must tell GCC to remove the libstdc++ include directories using -nostdinc++ and to not link libstdc++.so using -nodefaultlibs.


1 Answers

It is from C++11 inlined namespaces

libc++ has something like

namespace std {
    inline namespace __1 {
        ....

more at What are inline namespaces for?

like image 166
Severin Pappadeux Avatar answered Oct 19 '22 11:10

Severin Pappadeux