tensorflow-r1.4 c++ protobuf-3.4.0 bazel-0.5.4

protobuf
first restore protobuf to its original state

sudo apt-get remove libprotobuf-dev
sudo apt-get remove protobuf-compiler
sudo apt-get remove python-protobuf
sudo rm -rf /usr/local/bin/protoc -v 
sudo rm -rf /usr/bin/protoc -v 
sudo rm -rf /usr/local/include/google -v 
sudo rm -rf /usr/local/include/protobuf* -v 
sudo rm -rf /usr/local/lib/libproto* -v 
sudo rm -rf /usr/lib/libproto* -v 
sudo rm -rf /usr/include/google -v
sudo rm -rf /usr/include/protobuf* -v 
sudo rm -rf /usr/lib/x86_64-linux-gnu/libproto* -v
sudo apt-get autoremove

second install protobuf gcc5.5.0 g++5.5.0

sudo update-alternatives --config g++
sudo update-alternatives --config gcc
./autogen.sh
./configure
make -j11
make -j11 check
sudo make install
sudo ldconfig # refresh shared library cache

remove exist bazel

which bazel
rm -rf /xxx/bazel
rm -rf .bazel
sudo rm -rf .cache/bazel

bazel install

sudo apt-get install bazel 
sudo apt-get upgrade bazel

or bazel 0.5.4
ubuntu bazel install

sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
chmod +x bazel-<version>-installer-linux-x86_64.sh
./bazel-<version>-installer-linux-x86_64.sh --user
gedit ~/.bashrc
# bazel
export PATH="$PATH:$HOME/bin"
source ~/.bashrc

bazel upgrade

sudo apt-get upgrade bazel

tensorflow download

git clone  https://github.com/tensorflow/tensorflow
bash tensorflow/contrib/makefile/download_dependencies.sh

tensorflow configure

./configure
#/home/hgw/.pyenv/versions/2.7.15/bin/python
#/home/hgw/.pyenv/versions/2.7.15/envs/env2715/lib
#/home/hgw/.pyenv/versions/2.7.15/envs/env2715/lib/python2.7/site-packages/numpy/core/include
/usr/bin/python
/usr/lib/python2.7/dist-packages

get libtensorflow_cc.so for c++

bazel build --config=opt  //tensorflow:libtensorflow_cc.so

get libtensorflow.so for c

bazel build --config=opt  //tensorflow:libtensorflow.so

put .h .so in one file

#find ./ -name "*.h" | xargs -i cp --parents {} /home/hgw/test0/ -v
cd ~/tensorflow
mkdir -p local/lib
cp bazel-bin/tensorflow/libtensorflow_all.so local/lib 
mkdir -p local/include/google/tensorflow
cp -r tensorflow local/include/google/tensorflow
cp bazel-genfiles/tensorflow/core/framework/*.h local/include/google/tensorflow/tensorflow/core/framework
cp bazel-tensorflow-r1.4/tensorflow/core/kernels/*.h local/include/google/tensorflow/tensorflow/core/kernels
cp bazel-genfiles/tensorflow/core/lib/core/*.h local/include/google/tensorflow/tensorflow/core/lib/core
cp bazel-genfiles/tensorflow/core/protobuf/*.h local/include/google/tensorflow/tensorflow/core/protobuf
cp bazel-genfiles/tensorflow/core/util/*.h local/include/google/tensorflow/tensorflow/core/util
cp bazel-genfiles/tensorflow/cc/ops/*.h local/include/google/tensorflow/tensorflow/cc/ops
cp -r third_party local/include/google/tensorflow/

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(tensorflow_cpp)

set(CMAKE_CXX_STANDARD 11)

find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
set(EIGEN337_INCLUDE_DIRS /usr/local/include/eigen3)

include_directories(
        ${OpenCV_INCLUDE_DIRS}
        ${PROTOBUF_INCLUDE_DIRS}
        ${EIGEN337_INCLUDE_DIRS}
        /home/hgw/ubtrobot/hgwproject/TensorFlowCPP/tensorflow-r1.4/local/include/google/tensorflow
)
link_directories(/home/hgw/ubtrobot/hgwproject/TensorFlowCPP/tensorflow-r1.4/local/lib)

aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRCS)
add_executable(${PROJECT_NAME} ${DIR_SRCS})

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${PROTOBUF_LIBRARIES} tensorflow_cc tensorflow_framework)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值