Compile and install caffe in centos7 non-Internet Environment
Because the machine is password-sensitive and cannot connect to the Internet, the yum command is unavailable, and the process of configuring and installing caffe is complicated. All dependencies must be compiled manually. First, list the dependencies required by caffe:
- Boost
- Glog
- Protobuf
- Lmdb
- LevelDB
- Snappy
- Gflags
- BLAS
- Opencv
- HDF5
- Cuda
My cmake version: 2.8.12.2
All installation packages are uploaded to/usr/local to decompress and compile.
1. Boost:
Boost of bloggers
# tar jxvf boost_1_55_0.tar.bz2 # cd boost_1_55_0# ./bootstrap.sh # ./b2 # sudo ./b2 install
2. glog: The glog of the blogger
# tar zxvf glog-0.3.3.tar.gz # cd glog-0.3.3 # ./configure # make && make install
3. protobuf: protobuf of the blogger
# Tar-zxf protobuf-2.5.0.tar.gz # cd protobuf-2.5.0 #. /configure -- prefix =/usr/local/protobuf/# make & make install // Add the following statement to the environment variable # export PATH =/usr/local/protobuf /bin: $ PATH
4. lmdb
# unzip lmdb-mdb.master.zip# cd lmdb-mdb.master/libraries/liblmdb # make && make install
5. LevelDB of levelDB bloggers
# unzip leveldb-master.zip# cd leveldb-master# make# sudo cp -r include/leveldb /usr/local/include# cd out-shared # cp lib* /usr/local/lib
6. Snappy
# tar -zvxf snappy-1.1.2.tar.gz# cd snappy-1.1.2# ./configure # make# make install
7. gflags: The gflags of the blogger
# unzip gflags-master.zip # cd gflags-master # mkdir build && cd build # export CXXFLAGS="-fPIC"# cmake .. && make VERBOSE=1 # make && make install
After executing the export CXXFLAGS = "-fPIC" command, cmake has a problem (maybe you will not have this problem ):
The C++ compiler "/usr/bin/c++" is not able to compile a simple test program
It is always unable to solve the problem. It is decided not to execute export CXXFLAGS = "-fPIC". However, after gflags is compiled and installed successfully, the problem occurs during caffe Compilation:
Linking CXX shared library ../../lib/libcaffe-d.so/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC/usr/local/lib/libgflags.a: error adding symbols: Bad valuecollect2: error: ld returned 1 exit statusmake[2]: *** [lib/libcaffe-d.so.1.0.0-rc3] Error 1make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2make: *** [all] Error 2
This indicates that no shared library is generated during gflags compilation and gflags is re-compiled.
Solution:
# unzip gflags-master.zip # cd gflags-master # mkdir build && cd build # cmake .. -DBUILD_SHARED_LIB=ON# make VERBOSE=1 # make && make install
8. BLAS:
BLAS is used for matrix operations. Here I tried two blas types. Finally, I used openblas to complete compilation and installation.
First, I tried to install the atlas
Run the rpm command to install the package.rpm -ivh Atlas-2.2.1-2.l7.centos.src.rpm
After the installation is successful, the atlas directory is stored in/usr/lib64/atlas. However, the cmake error occurs when caffe is compiled:
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message): Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY)
Solution:Add-DAtlas =/usr/lib64/atlas after cmake...
However, problems occur during compilation:
../lib/libcaffe-d.so.1.0.0-rc3: undefined reference to `cblas_sgemv' ../lib/libcaffe-d.so.1.0.0-rc3: undefined reference to `cblas_dgemm' ../lib/libcaffe-d.so.1.0.0-rc3: undefined reference to `cblas_sscal' ../lib/libcaffe-d.so.1.0.0-rc3: undefined refere...
After checking the information, I think there are two possible errors: incomplete atlas installation and lack of dependencies, because the atlas rpm packages on github are in centos6.x and 5. the version I found on the Internet may need to install other atlas rpm packages. Second, in addition to installing atlas, you need to install a database called cblas. The specific cause of the problem failed to continue the research due to the time relationship, so I gave up atlas and chose OpenBLAS.
The blogger's OpenBLAS
# tar -xzvf OpenBLAS.tar.gz # make # make --PREFIX='usr/local/' install # cp lib* /usr/local/lib
OpenBLAS Installation Complete
9. There are many installation tutorials for Opencv. The blogs here mainly list the problems I encountered during installation.
The opencv version I used is 3.2.0. When cmake is used, a package named ippicv_linux_20151201.tgz will be downloaded from the Internet, but the machine cannot connect to the Internet. Therefore, the package cannot be downloaded, I found the package on the Internet on my machine (the package), put it under/usr/local/opencv-3.2.0/3 rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e, and re-cmake, successful.
Problem 1 during compilation
make[2]: *** [modules/gpu/CMakeFiles/opencv_gpu.dir/src/graphcuts.o] Error 1 make[1]: *** [modules/gpu/CMakeFiles/opencv_gpu.dir/all] Error 2 make: *** [all] Error 2
Solution: Add-D BUILD_opencv_gpu = off to Cmake (for testing without gpu training data)
- Problem 2 during compilation
Modules/core/CMakeFiles/cuda_compile.dir/_/dynamicuda/src/cuda /. /cuda_compile_generated_matrix_operations.cu.oarm-linux-gnueabihf-gcc: error: unrecognized command line option '-m64' CMake Error at cuda_compile_generated_matrix_operations.cu.o.cmake: 206 (message ): error generating/home/yy/opencv-2.4.9/build/modules/core/CMakeFiles/cuda_compile.dir/_/dynamicuda/src/cuda /. /cuda_compile_generated_matrix_operations.cu.omake [2]: *** [modules/core/CMakeFiles/cuda_compile.dir/_/dynamicuda/src/cuda /. /cuda_compile_generated_matrix_operations.cu.o] Error 1 make [1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 make: *** [all] Error 2
Solution: Add-D CMAKE_BUILD_TYPE = bulid-D CMAKE_INSTALL_PREFIX =/usr/local-D CUDA_GENERATION = Kepler .. "to Cmake .."
10. HDF5
HDF5 of the blogger
# Gunzip
11. Due to the CUDA installation on the machine used, the blogger did not perform this step.
Compile caffe: Change It In The Makefile. config file:
BLAS:=openBLAS_INCLUDE := /usr/local/includeBLAS_LIB := /usr/local/lib
# cmake .. -DBUILD_SHARED_LIB=ON -DBLAS=open -DOpenCV_DIR=/usr/local/opencv-3.2.0/build# make && make install
Common problem: the dependency library cannot be found in cmake. Solution: add the export Statement to the environment variable. For example, add the statement in/etc/profile.export PATH=/usr/local/protobuf/bin:$PATHOr explicitly specify the dependency location after the cmake statement, for example,-DOpenCV_DIR=/usr/local/opencv-3.2.0/build
References:
Http://blog.csdn.net/chang_ge/article/details/52650982 http://yongyuan.name/blog/compiling-cpp-code-using-caffe.html http://blog.csdn.net/s2392735818/article/details/49796017 http://stackoverflow.com/questions/15161278/compile-opencv-without-gpu http://opencv-users.1802565.n2.nabble.com/OpenCV-with-CUDA-4-1-Support-on-64bit-Ubuntu-11-10-td7304408.html http://blog.csdn.net/tjusxh/article/details/41944403 http://blog.csdn.net/hairetz/article/details/18049257 http://blog.csdn.net/luo6620378xu/article/details/8521223
Original article: http://blog.csdn.net/ChrisYoung95/article/details/70574844