- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您好,我正在尝试将 TensorFlow 用于 C/C++。目前我正在尝试编译他们在安装说明中提供的基本程序。
https://www.tensorflow.org/install/install_c
我在运行 Ubuntu 的 x86_64 机器上工作。我相信我正确安装了库。当我列出/usr/local/文件夹中的目录时,我在其中看到了 tensorflow。
$: ls /usr/local/include/
tensorflow
但是,当我尝试编译他们提供的基本程序时,gcc 和 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
安装时一切顺利,除了我按照建议运行 ldconfig 以安装到系统目录中。
$ 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
然而,这些文件似乎不会影响相关程序的编译。当我运行故障排除编译命令时,它似乎起作用了。我不确定这是为什么
g++ -I/usr/local/include -L/usr/local/lib hello_tf.cpp -ltensorflow
最佳答案
你的 hello_tf.cpp 文件被编译成一个叫做对象的东西。因为在你的程序内部,你调用的函数名称编译器无法在你的代码中找到链接器需要在其他地方找到它们以允许对象调用这些函数的代码。选项 L (-L/usr/local/lib) 告诉它应该在哪个目录中查找,l (-l tensorflow) 告诉它应该检查哪些模块。请记住,-l 应该出现在翻译单元 (hello_tf.cpp) 之后。
在此处发布问题之前,您应该做一些研究。您链接的页面用 export LIBRARY_PATH 替换了“-L”……但我认为如果没有 -l,您的程序将无法编译。
关于c++ - C/C++ TensorFlow hello_tf.c :(. text+0xa): 未定义对 `TF_Version' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47380096/
您好,我正在尝试将 TensorFlow 用于 C/C++。目前我正在尝试编译他们在安装说明中提供的基本程序。 https://www.tensorflow.org/install/install_c
我是一名优秀的程序员,十分优秀!