`std::basic_string` 和 `std::__1::basic_string` 有什么区别?

问题描述

ninja(版本:1.9.0)输出

mergetree_test.cpp:(.text+0x19f): undefined reference to `DB::executeQuery(std::string const&,DB::Context&,bool,DB::QueryProcessingStage::Enum,bool)'

nm -A mergetree_test.o | grep executeQuery | c++filt 输出

mergetree_test.o:                 U DB::executeQuery(std::basic_string<char,std::char_traits<char>,std::allocator<char> > const&,bool)

但是我从链接库中获得了输出,其中 executeQuery 使用相同的方法定义。

libdbms.a:executeQuery.cpp.o:0000000000008750 T DB::executeQuery(std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char> > const&,bool)

__1 是什么意思?我该如何解决问题?

解决方法

我怀疑您正在尝试组合使用 libc++ 和 libstdc++ 编译的库。

libc++ 将(几乎)所有符号放入 std::_1::,而 libstdc++ 将其符号放入 std::

,

你问了两个问题,所以我要回答主要问题(__1 是什么?):

__1 是位于 std 中的内联命名空间:

namespace std
{
    inline namespace __1
    {
        // string,...
    }
}

inline 意味着不必指定结构/函数/变量位于该命名空间中,因此可以简单地使用 std::string 而不是 std::__1::string

至于为什么会出现错误:如果您不提供一些代码,我们无法知道。