問題描述
我用的是c++11,但也有一些庫沒有為它配置,需要一些類型轉換.特別是我需要一種將 std::__cxx11::string
轉換為常規 std::string
的方法,但是谷歌搜索我找不到這樣做的方法并把前面的(string)
不起作用.
I use c++11, but also some libraries that are not configured for it, and need some type conversion. In particular I need a way to convert std::__cxx11::string
to regular std::string
, but googling I can't find a way to do this and putting (string)
in front does not work.
如果我不轉換,我會收到這樣的鏈接器錯誤:
If I do not convert I get linker errors like this:
undefined reference to `H5::CompType::insertMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, H5::DataType const&) const'
推薦答案
您是否可能使用 GCC 5?
Is it possible that you are using GCC 5?
如果您收到有關未定義引用符號的鏈接器錯誤,這些符號涉及 std::__cxx11 命名空間或標記 [abi:cxx11] 中的類型,那么這可能表明您正在嘗試將使用不同值編譯的目標文件鏈接在一起對于 _GLIBCXX_USE_CXX11_ABI 宏.當鏈接到使用舊版 GCC 編譯的第三方庫時,通常會發生這種情況.如果無法使用新 ABI 重建第三方庫,則需要使用舊 ABI 重新編譯代碼.
If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.
來源:GCC 5 發行說明/雙 ABI
定義以下宏之前包括任何標準庫頭應該可以解決您的問題:#define _GLIBCXX_USE_CXX11_ABI 0
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
這篇關于將 std::__cxx11::string 轉換為 std::string的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!