我正在将Tensorflow2共享库(*.so(文件链接到我的C++程序中。libtensorflow_cc和libtensorflow_framework.so使用bazel-3.7.2和gcc7.3,并链接到我的另一个库"libmyproj.so"。我想将这个libmyproj.so链接到我用相同gcc7.3构建的主程序。我已经尝试使用-D_GLIBCXX_USE_CXX11_ABI=0标志来实现ABI兼容性(来自https://www.tensorflow.org/install/source以及将std::__cxx11::string转换为std::string(,但没有成功。我被以下错误卡住了:
undefined reference to ml_model::ml_model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
undefined reference to ml_model::preprocess_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<float, std::allocator<float> >, int&, int&, std::vector<int, std::allocator<int> >&)'
undefined reference to ml_model::get_predictions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > int, std::vector<int, std::allocator<int> >)'
在函数std::__cxx11::basic_string<char,std::char_traits,std::分配器>*tensorflow::internal::MakeCheckOpString<长的int>(long const&,int const&mp;,char const*(':undefined reference to tensorflow::internal::CheckOpMessageBuilder::NewString[abi:cxx11]()'
关于为什么会发生这种情况,有什么建议吗?
检查libstdc++
版本是否正确您的问题可能是libstdc++
版本更高的tensorflow_cc.so
编译器,但您的构建环境libstdc++
更低,因此找不到一些符号。
- 获取libstdc++版本:
符号链接指向一个版本化的文件,在本例中为6.0.28bash$ /sbin/ldconfig -p | grep stdc++ libstdc++.so.6 (libc6,x86_64) => /lib/x86_64-linux-gnu/libstdc++.so.6 bash$ ls -l /lib/x86_64-linux-gnu/libstdc++.so.6 lrwxrwxrwx 1 root root 19 Jan 10 2021 /lib/x86_64-linux-gnu/libstdc++.so.6 -> libstdc++.so.6.0.28
- 更新
libstdc++
;如何做到这一点完全取决于你的发行版,但在谷歌上应该不难找到说明