【问题标题】:undefined reference to `(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' when using tensorflow_cc.so使用 tensorflow_cc.so 时对 `(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' 的未定义引用
【发布时间】:2021-07-19 09:40:23
【问题描述】:

我正在将 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/sourceConverting std::__cxx11::string to std::string),但没有任何成功。我遇到以下错误:

undefined reference to ml_model::ml_model(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)'undefined reference to ml_model::preprocess_data(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::vector&lt;float, std::allocator&lt;float&gt; &gt;, int&amp;, int&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt;&amp;)'undefined reference to ml_model::get_predictions(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::vector&lt;std::pair&lt;int, int&gt;, std::allocator&lt;std::pair&lt;int, int&gt; &gt; int, std::vector&lt;int, std::allocator&lt;int&gt; &gt;)' 在函数 std::__cxx11::basic_string* tensorflow::internal::MakeCheckOpString(long const&, int const&, char const*)': undefined reference to tensorflow::internal::CheckOpMessageBuilder::NewString[abi:cxx11]()'

关于为什么会发生这种情况的任何建议?

【问题讨论】:

    标签: c++11 gcc tensorflow2.0


    【解决方案1】:

    检查libstdc++版本是否正确。你的问题可能是tensorflow_cc.so编译器的libstdc++版本较高,但你的build env libstdc++较低,所以找不到一些符号。

    • 获取 libstdc++ 版本:
      bash$ /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
      
      符号链接指向版本化文件,在本例中为 6.0.28。
    • 更新libstdc++;如何执行此操作完全取决于您的发行版,但在 Google 中应该不难找到说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多