ubuntu18.04編譯最新caffe錯誤修正

這裏記錄些編譯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

就好
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章