gpt4 book ai didi

c++ - C/C++ TensorFlow hello_tf.c :(. text+0xa): 未定义对 `TF_Version' 的引用

转载 作者:太空狗 更新时间:2023-10-29 11:49:19 25 4
gpt4 key购买 nike

您好,我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com