1. 程式人生 > >c++ - Linking problems due to symbols with abi::cxx11?

c++ - Linking problems due to symbols with abi::cxx11?

() 重新 fine protobuf undefined all ems -s num

看錯誤內容:

/data/projects/LipReadingSDKGPU/lib/cwlibs/libLipReading.so: undefined reference to `tensorflow::Status::ToString[abi:cxx11]() const/data/projects/LipReadingSDKGPU/lib/cwlibs/libLipReading.so: undefined reference to `tensorflow::ReadBinaryProto(tensorflow::Env*, std::__cxx11::basic_string<char, std::char_traits<char
>, std::allocator<char> > const&, google::protobuf::MessageLite*)/data/projects/LipReadingSDKGPU/lib/cwlibs/libLipReading.so: undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]/data/projects/LipReadingSDKGPU/lib/cwlibs/libLipReading.so: undefined reference to `tensorflow::internal
::CheckOpMessageBuilder::NewString[abi:cxx11]()/data/projects/LipReadingSDKGPU/lib/cwlibs/libLipReading.so: undefined reference to `tensorflow::strings::StrCat[abi:cxx11](tensorflow::strings::AlphaNum const&)

stackoverflow上一個友人的解釋:

I suspect this is a C++ ABI issue. The ABI for std::string has changed in
GCC 5 (related to C++11 requirements, but it applies even if you arent using C++11). See: https://gcc.gnu.org/gcc-5/changes.html#libstdcxx If libprotobuf was built with GCC 4.x or prior, but your app is built with GCC 5, then you will see problems, because libprotobuf uses std::string in its interface. You have two options: 1.Rebuild libprotobuf with GCC 5 (but now any apps built with GCC 4 wont work with the new version of libprotobuf). 2.Build you app with -D_GLIBCXX_USE_CXX11_ABI=0 as described at the above link. This will force GCC to use the old ABI version.

這個錯誤是在我把gcc4.8編的工程遷移到ubuntu16.04(gcc5.4)上編譯時候發生的。這是C++ ABI一個錯誤,gcc4升gcc5時,std::string庫接口做了遷移,而我工程中用了三方庫tensorflow和protobuf,protobuf中用到了std::string。已經編好的tensorflow是用gcc4.8編的,gcc5上鏈接,接口對不上。兩種解決方案:一種用gcc5重新編譯三方庫和工程,另一種就是在工程的編譯選項(而不是鏈接選項)上加上-D_GLIBCXX_USE_CXX11_ABI=0參數,強制使用舊接口,問題解決。

更詳細的解釋可以參考:http://www.itkeyword.com/doc/8367047421581508x309/linking-problems-due-to-symbols-with-abicxx11

c++ - Linking problems due to symbols with abi::cxx11?