0

I have the following .sh file (from here).

g++ -c -pipe -g -std=gnu++11 -Wall -W -fPIC -I. -I./tensorflow
-I./tensorflow/bazel-tensorflow/external/eigen_archive -I./tensorflow/bazel-tensorflow/external/protobuf/src -I./tensorflow/bazel-genfiles -o main.o ./main.cpp

g++  -o Tutorial main.o   -L./tensorflow/bazel-bin/tensorflow
-ltensorflow_cc

cp ./tensorflow/bazel-bin/tensorflow/libtensorflow* .

When I try to run this .sh file from terminal I got an error. Therefore I executed the commands one by one. First one worked fine and I saw that when I run the second command ( g++ -o Tutorial main.o -L./tensorflow/bazel-bin/tensorflow -ltensorflow_cc) I get the following error.

/usr/bin/ld: main.o: undefined reference to symbol '_ZN10tensorflow3Env19NewRandomAccessFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPSt10unique_ptrINS_16RandomAccessFileESt14default_deleteISA_EE'
libtensorflow_framework.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I saw the answer here and I see it as closely related to mine. But I cannot figure out how to adapt it to my problem.

Can someone please help with this?

Satinger
  • 123
  • 1
  • 8
  • @PythEch I did that and some folders got created inside my tensorflow folder (bazel-bin, bazel-genfiles, bazel-out, bazel-tensorflow, and bazel-testlogs). Is that correct? – Satinger Mar 26 '18 at 19:17
  • The linker is saying that the linkage requires shared library `libtensorflow_framework.so` (presumably because `-ltensorflow_cc` depends on it and requests it) but is not given in your commandline. This should be solved by adding `-ltensorflow_framework` at the end, with an additional `-L` option if necessary. – Mike Kinghan Mar 26 '18 at 19:33
  • @MikeKinghan thanks a lot I hope it works. I am away now and will let you know when I test it tomorrow. – Satinger Mar 26 '18 at 20:46
  • @MikeKinghan thanks a lot it worked. If you can add it as an answer I can mark it correct. Thank you again. – Satinger Mar 27 '18 at 10:27
  • Your're welcome. Made it an answer. – Mike Kinghan Mar 27 '18 at 10:30

2 Answers2

2

The linker is saying that the linkage requires shared library libtensorflow_framework.so (presumably because -ltensorflow_cc depends on it and requests it) but is not given in your commandline. This should be solved by adding -ltensorflow_framework at the end, with an additional -L option if necessary.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
0

I was too getting the same error.

If you are using tensorflow 2, then you need to link .so.2 files. You should find them in the bazel build directory. For me it is : /tmp/bazel/output/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow

I linked the files using the below in my CMAKE: file(GLOB LIBRARIES "${bazel_bin}/tensorflow/*.so.2") message("LIBRARIES = ${LIBRARIES}")

s510
  • 2,271
  • 11
  • 18