这里记录些编译caffe时的报错:
每次报错修改好后,别忘了先make clean,再make all -j4:
1.主要是cuda,nvcc路径问题,解决方案:
就是找到东西,把它复制到caffe想要的路径或者修改make.config文件中相应的库路径,个人比较喜欢复制的方法。。。
2.还有就是我用的CUDA9.1不再支持compute_20架构了,所以把以下两行注释了就好了。
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
3. g++问题:
有两种方法,
方法一:版本要低于要求,我用的g++-5 gcc-5,结果5不行,又现装的4.8
sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
然后,在make.config文件中指定版本
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
CUSTOM_CXX := g++-4.8
方法二:去掉这个错误提醒
我是apt安装的nvidia-cuda-tool,所以是在/usr/include/crt/host_config.h
普遍的源码编译的是在/usr/local/cuda/include/host_config.h
我的是
#if __GNUC__ > 6
#error -- unsupported GNU version! gcc versions later than 6 are not supported!
#endif /* __GNUC__ > 6 */
大家可能是
< #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)
---
> //#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)
115c115
< #error -- unsupported GNU version! gcc versions later than 4.9 are not supported!
---
> //#error -- unsupported GNU version! gcc versions later than 4.9 are not supported!
117c117
< #endif /* __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) */
---
> //#endif /* __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) */
4.大量 undefined reference to
这是是很多辅助库没装到它能找到的地方的问题:
比如:
undefined reference to `boost::archive 等一大长串
就是没找到boost的那一套,所以就先找一下它在哪里:
locate boost
看到它集中在两个地方/usr/lib/x86_64-linux-gnu/和/usr/include/
所以把他们分别加到makefile.config文件中相应的位置,让caffe找到他们:
# Whatever else you find you need goes here.INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/ /usr/include/ /usr/lib/x86_64-linux-gnu/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/ /usr/lib/x86_64-linux-gnu/
并且在Makefile中制定加上需要的库:
CUDA_LIB_DIR += $(CUDA_DIR)/lib
INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include
ifneq ($(CPU_ONLY), 1)
INCLUDE_DIRS += $(CUDA_INCLUDE_DIR)
LIBRARY_DIRS += $(CUDA_LIB_DIR)
LIBRARIES := cudart cublas curand
endif
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 \
boost_serialization boost_program_options
最后,
make all -j8
make pycaffe -j8
就好