Hello I am trying to use TensorFlow for C/C++. Currently I am trying to get the basic program they offer in their installation instructions to compile.
https://www.tensorflow.org/install/install_c
I am working on x86_64 machine running Ubuntu. I believe I installed the library properly. When I list the directories in the /usr/local/ folder, I see tensorflow in there.
$: ls /usr/local/include/
tensorflow
However, when I attempt the compile the basic program they offer, it fails with both gcc and g++
$: gcc -o test hello_tf.cpp
/tmp/cczK3WZs.o: In function `main':
hello_tf.cpp:(.text+0x5): undefined reference to `TF_Version'
collect2: error: ld returned 1 exit status
$: g++ -o test hello_tf.cpp
/tmp/ccl7FitR.o: In function `main':
hello_tf.cpp:(.text+0x5): undefined reference to `TF_Version'
collect2: error: ld returned 1 exit status
Everything went smoothly on install except when I ran ldconfig as suggested for installing into a system directory.
$ sudo ldconfig /sbin/ldconfig.real:
/usr/lib/libusbredirparser.so.1 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libid3tag.so.0 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libusbg.so.0 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libusbmuxd.so.2 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libmtp.so.9 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libmad.so.0 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libusb-1.0.so.0 is not a symbolic link
/sbin/ldconfig.real: /usr/lib/libusbredirhost.so.1 is not a symbolic link
Nevertheless, these files do not seem like they should affect the compilation of the program in question. When I run the troubleshooting compilation command, it seems to work. I am not sure why this is
g++ -I/usr/local/include -L/usr/local/lib hello_tf.cpp -ltensorflow
I faced the same issue but my case is different. I don't understand why but the order or arguments to g++ is different on CentOS and Ubuntu.
This is no errors on CentOS, but fails on Ubuntu:
#source file comes last
g++ -ltensorflow -o prog prog.cpp
It must be in this order on Ubuntu:
#source file comes first
g++ prog.cpp -o prog -ltensorflow
Your hello_tf.cpp file is compiled to something called object. Because inside of your program you called functions names compiler could not find inside your code linker needs to look somewhere else to find them to allow object to call the code of those functions. Option L (-L/usr/local/lib) tells it in which directories it should look for and l (-l tensorflow) tells it which modules it should check. Remember that -l should appear AFTER translation unit (hello_tf.cpp).
You should do a little bit of research before posting question here. Page you linked substitutes "-L" with export LIBRARY_PATH ... but I don't think your program will ever compile without -l.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With