0

I want to perform some preprocessing, with opencv, on an image which will be fed to a tensorflow model. The preprocessing part reads in a .png file, the code works as a standalone program, but I want to use it inside the program that runs the tensorflow model, so I generated an object file as below. The program for preprocessing works perfectly as standalone.

g++ -std=c++11 preProcess.cpp -I/home/dpk/anaconda2/include/libpng16 -I/usr/local/include/opencv2 -L/home/dpk/anaconda2/lib -lpng16 -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -c

The tensorflow program, Inference.cc was compiled as below

g++ -std=c++11 preProcess.o Inference.cc -I/home/dpk/anaconda2/include/libpng16 -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/local/include/tf -I/usr/local/include/eigen3 -I/usr/local/include/tf/bazel-genfiles -g -Wall -D_DEBUG -Wshadow -Wno-sign-compare -w  -L/usr/local/lib/libtensorflow_cc -L/home/dpk/anaconda2/lib -lpng16 -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_flann -lopencv_core `pkg-config --cflags --libs protobuf` -ltensorflow_cc -o inference

This throws the following error

/usr/local/lib/libtensorflow_cc.so: undefined reference to `std::thread::_State::~_State()@GLIBCXX_3.4.22'
/usr/local/lib/libtensorflow_cc.so: undefined reference to `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())@GLIBCXX_3.4.22'
/usr/local/lib/libtensorflow_cc.so: undefined reference to `typeinfo for std::thread::_State@GLIBCXX_3.4.22'

This error seems to be caused by linking -L/home/dpk/anaconda2/lib, because compilation goes smoothly when I don't link that folder , but then the program fails to read .png files. Hence it appears that, that folder is necessary for handling .png.

I need my program to read .png files as well as run the tensorflow model. How can I make both of them work?

Effective_cellist
  • 1,098
  • 1
  • 19
  • 39
  • 1
    It seems to be part of the C++11 standard. Try using the flag `-std=c++11` – bracco23 Jul 27 '17 at 10:19
  • @bracco23 Tried that, throws the same error. I'll edit my question to include that flag – Effective_cellist Jul 27 '17 at 10:31
  • Might look silly, but check if you have the header `#include ` in your file. – The Apache Jul 27 '17 at 10:38
  • @TheApache Thanks for the suggestion, that didn't help either, got the same error. – Effective_cellist Jul 27 '17 at 10:47
  • Try passing `-lstdc++` to the linker, so it links to the standard library. – tambre Jul 27 '17 at 10:59
  • @tambre Thank you for the suggestion, unfortunately, I get the same error with `-lstdc++` – Effective_cellist Jul 27 '17 at 11:03
  • For me, it sounds like `libtensorflow_cc.so` is built for another version of standard C++ library than you have currently installed and link to your application. Btw. I found a similar question: [SO: Getting undefined reference to std::thread::_M_start_thread](https://stackoverflow.com/q/38226993/7478597) (though the answer was not accepted). You could check this using the "How to" I found in [SO: How do you find what version of libstdc++ library is installed on your linux machine?](https://stackoverflow.com/q/10354636/7478597). – Scheff's Cat Jul 27 '17 at 13:14
  • 1
    This happened to me because my $PATH was pointing to an old version of gcc. `which gcc` told me that. – Katu Mar 07 '18 at 15:01

1 Answers1

1

Tensorflow is built with gcc 6 because there is a linker bug which prevents the successful compilation with gcc 5. You must build and link your program with gcc 6 to avoid this linker error.

kecsap
  • 350
  • 3
  • 8