linux tensorflow2.4.0 c++ 编译

1. bazel 版本要对应tensorflow的要求

2.tensorflow 源码

3.eigen

4.protobuf 版本要对应tensorflow的要求(workspace.bzl 提到了这个要求)

源码编译

 

参考:

https://blog.csdn.net/luo841297935/article/details/104417495

 

其他

1.CMakeLists.txt

cmake_minimum_required (VERSION 2.8.8)
project (example)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -W")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D_GLIBCXX_USE_CXX11_ABI=0 -W")
aux_source_directory(./src DIR_SRCS)
link_directories(/media/tq/keepit/2020/9/10/tensorflow/bazel-bin/tensorflow)
include_directories(
  【tensorflow path】/tensorflow/
  【tensorflow path】/tensorflow/tensorflow/
  【tensorflow path】/tensorflow/bazel-bin/
  【tensorflow path】/tensorflow/bazel-bin/tensorflow
  /usr/local/include/eigen3
  )
add_executable(example  2.cpp) 
target_link_libraries(example tensorflow_cc tensorflow_framework)

在项目目录下写cmakelist
 

mkdir build
cd build
cmake ..
make
./emample

2.编译过程内存不足时

设置10g 的swap

[root@Byrd byrd]# free -m
             total       used       free     shared    buffers     cached
Mem:           512        108        403          0          0         28
-/+ buffers/cache:         79        432
Swap:            0          0          0
[root@Byrd ~]# mkdir /opt/images/
[root@Byrd ~]# rm -rf /opt/images/swap
[root@Byrd ~]# dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 82.7509 s, 25.3 MB/s
[root@Byrd ~]# mkswap /opt/images/swap
mkswap: /opt/images/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=59daeabb-d0c5-46b6-bf52-465e6b05eb0b
[root@hz mnt]# swapon /opt/images/swap
[root@hz mnt]# free -m
             total       used       free     shared    buffers     cached
Mem:           488        481          7          0          6        417
-/+ buffers/cache:         57        431
Swap:          999          0        999

https://blog.csdn.net/taiyang1987912/article/details/41695895/

3.有可能要解决网络问题

4.bazel cpu

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

 

你可能感兴趣的:(linux tensorflow2.4.0 c++ 编译)