1

I am working on linking Tensorflow2 shared libraries (*.so) files into my C++ program. The libtensorflow_cc and libtensorflow_framework.so use bazel-3.7.2 and gcc7.3 and is linked to another library I have ‘libmyproj.so’. I want to link this libmyproj.so to my main program which are built with the same gcc7.3. I have tried using the -D_GLIBCXX_USE_CXX11_ABI=0 flag for ABI compatibility (from https://www.tensorflow.org/install/source and Converting std::__cxx11::string to std::string) but without any success. I am stuck at the following error:

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> >)' in function std::__cxx11::basic_string<char, std::char_traits, std::allocator >* tensorflow::internal::MakeCheckOpString<long, int>(long const&, int const&, char const*)': undefined reference to tensorflow::internal::CheckOpMessageBuilder::NewString[abi:cxx11]()'

Any suggestions on why this is happening?

Ashwin Tr
  • 11
  • 1
  • 2

1 Answers1

2

Check if the libstdc++ version is correct。 Your problem may be the tensorflow_cc.so compiler with higher libstdc++ version, but your build env libstdc++ is lower, so some symbols will not be found.

  • Get libstdc++ version:
    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
    
    The symlink points to a versioned file, in this case 6.0.28.
  • Update libstdc++; how to do this exactly depends on your distro, but instructions should not be hard to find in Google.
tripleee
  • 175,061
  • 34
  • 275
  • 318
yangchao
  • 33
  • 5