Centos 编译TensorFlow C/C++库 libtensorflow.so libtensorflow_framework.so

  • 安装依赖

yum -y install automake libtool libsysfs libxslt-devel libffi libffi-devel python-devel gcc openssl openssl-devel sqlite-devel

pip install six numpy wheel coverage mock

  • 安装CMake

从https://cmake.org/download/选择最新的版本

wget https://github.com/Kitware/CMake/releases/download/v3.14.0-rc4/cmake-3.14.0-rc4-Linux-x86_64.tar.gz

tar -xvf cmake-3.14.0-rc4-Linux-x86_64.tar.gz

mv cmake-3.14.0-rc4-Linux-x86_64 /usr/local/share/cmake

ln -s /usr/local/share/cmake/bin/ccmake /usr/bin/ccmake

ln -s /usr/local/share/cmake/bin/cmake /usr/bin/cmake

ln -s /usr/local/share/cmake/bin/ctest /usr/bin/ctest

  • 安装java

yum -y install java-1.8.0-openjdk*

  • 安装Bazel

从https://github.com/bazelbuild/bazel/releases选择合适的版本,具体版本对应关系在https://tensorflow.google.cn/install/source,tensorflow r1.12对应的应是bazel 0.15.0

wget https://github.com/bazelbuild/bazel/releases/download/0.15.0/bazel-0.15.0-installer-linux-x86_64.sh

sh bazel-0.15.0-installer-linux-x86_64.sh --prefix=/usr/local/share/bazel

ln -s /usr/local/share/bazel/bin/bazel /usr/bin/bazel

  • 下载TensorFlow

git clone https://github.com/tensorflow/tensorflow

或者

git clone https://jhc888007%40163.com:[password]@github.com/tensorflow/tensorflow

cd tensorflow

git checkout r1.12

./configure

接下来有一系列设置(这步好像不是必须的?),不懂的可以用默认值

  • 编译C库

cd tensorflow

bazel build :libtensorflow.so

在../bazel-bin/tensorflow/生成libtensorflow.so和libtensorflow_framework.so

  • 编译C++库

cd tensorflow

bazel build :libtensorflow_cc.so

在../bazel-bin/tensorflow/生成libtensorflow_cc.so和libtensorflow_framework.so

  • 安装依赖

cd contrib/makefile

./build_all_linux.sh

  • 安装Eigen

cd downloads/eigen

mkdir build

cd build

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/share/eigen ..

make install

cd /usr/local/include

ln -s ../share/eigen/include/eigen3/Eigen

ln -s ../share/eigen/include/eigen3/unsupported

  • 安装Protobuf(实践证明对于1.12版本不兼容,行不通)

cd downloads/protobuf

./autogen.sh

./configure --prefix=/usr/local/share/protobuf

make && make install

如果不成功则make clean,再重新make

vim /etc/profile

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/protobuf/lib
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/share/protobuf/lib
export PATH=$PATH:/usr/local/share/protobuf/bin
export PKG_CONFIG_PATH=/usr/local/share/protobuf/lib/pkgconfig/
  • 安装Protobuf(手动)

在https://github.com/protocolbuffers/protobuf/releases找到合适版本

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.0/protobuf-all-3.6.0.tar.gz

tar -xvf protobuf-all-3.6.0.tar.gz

cd protobuf-3.6.0/ 

./configure --prefix=/usr/local/share/protobuf

make && make check && make install

vim /etc/profile

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/protobuf/lib
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/share/protobuf/lib
export PATH=$PATH:/usr/local/share/protobuf/bin
export PKG_CONFIG_PATH=/usr/local/share/protobuf/lib/pkgconfig/
  •  如果已经有相同系统环境编译好的tensorflow包,则只需要安装依赖环境,然后将已安装的Eigen拷贝到新机器对应位置,然后将编译好的tensorflow包拷贝到python安装目录lib目录下

 

 

 

Centos 安装TensorFlow

Centos 编译TensorFlow C/C++库 libtensorflow.so libtensorflow_framework.so

Centos C/C++库 libtensorflow.so libtensorflow_framework.so 测试

 

 

参考文献:

https://www.cnblogs.com/hrlnw/p/7007648.html

https://www.jianshu.com/p/d46596558640

https://blog.csdn.net/qq_37674858/article/details/81095101

http://www.cnblogs.com/zjutzz/p/10182099.html

https://blog.csdn.net/u010700335/article/details/69422282/

https://www.cnblogs.com/hrlnw/p/7383951.html

https://blog.csdn.net/qq_29936933/article/details/82107861

https://blog.csdn.net/laowulong350/article/details/79001511

https://tensorflow.google.cn/install/source_windows

转载于:https://www.cnblogs.com/jhc888007/p/10518425.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值