我正在tensorflow框架中编写C++代码,我想使用使用makefile编写的动态库。 在源代码中我放置了头文件的路径:
#include "tensorflow/cc/include/libtrading/proto/tf_fix_client.h"
使用名为 fix_client(int argc, char **argv) 的函数 在 BUILD 文件中,我放置了动态库的路径,称为 libtrading.so:
cc_binary(
name = "session",
srcs = ["work/session.cc"],
copts = tf_copts(),
linkopts = [
"-lpthread",
"-lm",
#for libtrading
"-L/home/alessandro_mercadante/tensor_flows/tensorflow/tensorflow/cc/include/",
"-ltrading",
],
...
bazel-build 检索到以下错误:
bazel-out/local_linux-opt/bin/tensorflow/cc/_objs/session/tensorflow/cc/work/session.o: In function `main':
session.cc:(.text.startup.main+0x2b): undefined reference to `fix_client(int, char**)'
collect2: error: ld returned 1 exit status
最佳答案
Bazel 要求声明所有依赖项,因此 TensorFlow 库应位于您的 deps 属性中。您的目标似乎并非如此(尤其是 tensorflow 包含的标志不合适)。
快速查看 TensorFlow 构建文件后,我会说它需要以下 deps 属性:
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/core:kernels",
"//tensorflow/core:tensorflow",
],
但是我对 TensorFlow 本身真的很不熟悉。
您的 cc_binary 的 deps 属性是什么?
关于c++ - tensorflow和bazel "undefined reference to"编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33900842/