c++ - tensorflow和bazel "undefined reference to"编译错误

标签 c++ tensorflow bazel

我正在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/

相关文章:

python-3.x - tf.global_variables_initializer() 不起作用

python - 使用神经网络学习分类值的分布

java - 如何在 Android Studio 中使用 FCM 和 Bazel?

c++ - 使用Bazel编译QT应用程序时访问资源

c++ - 将对象的第一个字段转换为对象的类型真的安全吗?

c++ - 如何在另一个项目的dll中添加调用函数

python - Keras,如何使用移除最后一层的模型进行预测

ubuntu - 无法使用 apt-get 在 Ubuntu 14.04 上安装 bazel

c++ - 如何在不更改给定代码的情况下将自定义 vector<typename> 转换为 STL vector<long> 或从 STL vector<long> 转换?

c++ - 在 float vector 中找到众数