如何为tensorflow构建c库

时间:2018-04-12 04:35:21

标签: tensorflow

我已经完成了构建tensorflow的步骤,并且它在python中工作。现在我如何构建我想要使用的C张量流库?

$ gcc -I../tensorflow -ltensorflow g.c
/usr/bin/ld: cannot find -ltensorflow
collect2: error: ld returned 1 exit status

2 个答案:

答案 0 :(得分:4)

要从源代码构建C库,请遵循大多数说明for building TensorFlow from source,除了不构建pip包,构建打包共享库和C API头文件的tarball:

bazel build -c opt //tensorflow/tools/lib_package:libtensorflow

这将产生一个tarball:

bazel-bin/tensorflow/tensorflow/tools/lib_package/libtensorflow.tar.gz

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md

中的更多详情

使用上述过程构建release binaries

希望有所帮助。

答案 1 :(得分:0)

您需要构建2个库:

  • libtensorflow_framework.so
  • libtensorflow.so

要构建它们,你必须使用bazel

bazel build //tensorflow:libtensorflow_framework.so
bazel build //tensorflow:libtensorflow.so

一旦两个库的构建过程结束,您必须让链接器知道这些库的位置,因此您必须相应地升级LIBRARY_PATHLD_LIBRARY_PATH

TENSORFLOW_LIB = "/path/of/tensorflow/bazel-bin/tensorflow/"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${TENSORFLOW_LIB}`
export LIBRARY_PATH=${LIBRARY_PATH}:${TENSORFLOW_LIB}