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)
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页