c++ – Linking problems due to symbols with abi::cxx11详解程序员

看错误内容:

/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 aren't 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 won't 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/8367047421581508×309/linking-problems-due-to-symbols-with-abicxx11

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/2717.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论