Problem in building matcaffe

139 views
Skip to first unread message
Assigned to mih...@gmail.com by me

rohit bharadwaj

unread,
Dec 2, 2020, 5:46:58 AM12/2/20
to Caffe Users
Hey all, 

Thank you for taking your time reading this, I'm stuck at building matcaffe, Im using Linux (Manjaro KDE) and i was able to build caffe using make all, make test, make runtest. Everything worked fine, but I'm not able to build matcaffe. I'm really new to building software from source and still learning how to do it properly, so please excuse me if my question is trivial. 

Here is the console logs which I'm getting, any help would be appreciated.

Logs: 
MEX matlab/+caffe/private/caffe_.cpp
Building with 'g++'.
Warning: gcc version '10.2.0' not supported. See https://www.mathworks.com/support/compilers/current_release
.
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemm<float>
(CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, float, float const*, float const*, float, float*)':
math_functions.cpp:(.text+0x137): undefined reference to `cblas_sgemm'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemm<double
>(CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, double, double const*, double const*, double, double*)':
math_functions.cpp:(.text+0x187): undefined reference to `cblas_dgemm'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemv<float>
(CBLAS_TRANSPOSE, int, int, float, float const*, float const*, float, float*)':
math_functions.cpp:(.text+0x1bc): undefined reference to `cblas_sgemv'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemv<double
>(CBLAS_TRANSPOSE, int, int, double, double const*, double const*, double, double*)':
math_functions.cpp:(.text+0x1ec): undefined reference to `cblas_dgemv'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<float
>(int, float, float const*, float, float*)':
math_functions.cpp:(.text+0x2e3): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<doubl
e>(int, double, double const*, double, double*)':
math_functions.cpp:(.text+0x344): undefined reference to `cblas_dscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<float
>(int, float, float const*, float*)':
math_functions.cpp:(.text+0x3e1): undefined reference to `cblas_scopy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<doubl
e>(int, double, double const*, double*)':
math_functions.cpp:(.text+0x431): undefined reference to `cblas_dcopy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_axpy<float>(int
, float, float const*, float*)':
math_functions.cpp:(.text+0x20f): undefined reference to `cblas_saxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_axpy<double>(in
t, double, double const*, double*)':
math_functions.cpp:(.text+0x22f): undefined reference to `cblas_daxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_scal<float>(int
, float, float*)':
math_functions.cpp:(.text+0x2a6): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_scal<double>(in
t, double, double*)':
math_functions.cpp:(.text+0x2b6): undefined reference to `cblas_dscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<float
>(int, float, float const*, float, float*)':
math_functions.cpp:(.text+0x30d): undefined reference to `cblas_saxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<doubl
e>(int, double, double const*, double, double*)':
math_functions.cpp:(.text+0x36f): undefined reference to `cblas_daxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `float caffe::caffe_cpu_strided_do
t<float>(int, float const*, int, float const*, int)':
math_functions.cpp:(.text+0x381): undefined reference to `cblas_sdot'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `double caffe::caffe_cpu_strided_d
ot<double>(int, double const*, int, double const*, int)':
math_functions.cpp:(.text+0x391): undefined reference to `cblas_ddot'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `float caffe::caffe_cpu_asum<float
>(int, float const*)':
math_functions.cpp:(.text+0x3a6): undefined reference to `cblas_sasum'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `double caffe::caffe_cpu_asum<doub
le>(int, double const*)':
math_functions.cpp:(.text+0x3b6): undefined reference to `cblas_dasum'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<float
>(int, float, float const*, float*)':
math_functions.cpp:(.text+0x3fd): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<doubl
e>(int, double, double const*, double*)':
math_functions.cpp:(.text+0x44d): undefined reference to `cblas_dscal'
collect2: error: ld returned 1 exit status

make: *** [Makefile:541: matlab/+caffe/private/caffe_.mexa64] Error 255

Tamas Nemes

unread,
Dec 2, 2020, 4:58:27 PM12/2/20
to Caffe Users
Well, the first thing I would try is update GCC (your compiler) to the suitable version as the error message says. It is very likely that the other errors are caused by this.
If you take a look at the site the error message provided (https://www.mathworks.com/support/compilers/current_release), there it says the current GCC version has to be 8.3. If you do a bit of investigating, you can find out how to change your compiler's version:

sudo apt-get install gcc-8 g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 40
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 40
sudo update-alternatives --set c++ /usr/bin/g++

Although this gives you version 8.4, it should be no big problem. Please try to apply above workaround to see if it works and if not, what are the error messages given.

Regards,
Tamas

rohit bharadwaj

unread,
Dec 3, 2020, 2:54:21 AM12/3/20
to Caffe Users
I thank you so much for taking your time in going through my problem. I tried to do what you suggested just now, ofcourse since I'm not on debian/ubuntu based distro, I had to download gcc-8 from AUR and create the links to the old version. Now I'm sure that I'm using GCC/g++ 8.4. But I'm still facing errors, I really don't know how to proceed with this. I'm using OpenBlas if that is of any help. Anyway here is the error logs after running make matcaffe

MEX matlab/+caffe/private/caffe_.cpp
Building with 'g++'.
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemm<float>(CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, float, float const*, float const*, float, float*)':
math_functions.cpp:(.text+0x137): undefined reference to `cblas_sgemm'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemm<double>(CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, double, double const*, double const*, double, double*)':
math_functions.cpp:(.text+0x187): undefined reference to `cblas_dgemm'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemv<float>(CBLAS_TRANSPOSE, int, int, float, float const*, float const*, float, float*)':
math_functions.cpp:(.text+0x1bc): undefined reference to `cblas_sgemv'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_gemv<double>(CBLAS_TRANSPOSE, int, int, double, double const*, double const*, double, double*)':
math_functions.cpp:(.text+0x1ec): undefined reference to `cblas_dgemv'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<float>(int, float, float const*, float, float*)':
math_functions.cpp:(.text+0x2e3): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<double>(int, double, double const*, double, double*)':
math_functions.cpp:(.text+0x344): undefined reference to `cblas_dscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<float>(int, float, float const*, float*)':
math_functions.cpp:(.text+0x3e1): undefined reference to `cblas_scopy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<double>(int, double, double const*, double*)':
math_functions.cpp:(.text+0x431): undefined reference to `cblas_dcopy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_axpy<float>(int, float, float const*, float*)':
math_functions.cpp:(.text+0x20f): undefined reference to `cblas_saxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_axpy<double>(int, double, double const*, double*)':
math_functions.cpp:(.text+0x22f): undefined reference to `cblas_daxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_scal<float>(int, float, float*)':
math_functions.cpp:(.text+0x2a6): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_scal<double>(int, double, double*)':
math_functions.cpp:(.text+0x2b6): undefined reference to `cblas_dscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<float>(int, float, float const*, float, float*)':
math_functions.cpp:(.text+0x30d): undefined reference to `cblas_saxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_axpby<double>(int, double, double const*, double, double*)':
math_functions.cpp:(.text+0x36f): undefined reference to `cblas_daxpy'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `float caffe::caffe_cpu_strided_dot<float>(int, float const*, int, float const*, int)':
math_functions.cpp:(.text+0x381): undefined reference to `cblas_sdot'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `double caffe::caffe_cpu_strided_dot<double>(int, double const*, int, double const*, int)':
math_functions.cpp:(.text+0x391): undefined reference to `cblas_ddot'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `float caffe::caffe_cpu_asum<float>(int, float const*)':
math_functions.cpp:(.text+0x3a6): undefined reference to `cblas_sasum'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `double caffe::caffe_cpu_asum<double>(int, double const*)':
math_functions.cpp:(.text+0x3b6): undefined reference to `cblas_dasum'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<float>(int, float, float const*, float*)':
math_functions.cpp:(.text+0x3fd): undefined reference to `cblas_sscal'
/usr/bin/ld: .build_release/lib/libcaffe.a(math_functions.o): in function `void caffe::caffe_cpu_scale<double>(int, double, double const*, double*)':
math_functions.cpp:(.text+0x44d): undefined reference to `cblas_dscal'
collect2: error: ld returned 1 exit status

make: *** [Makefile:541: matlab/+caffe/private/caffe_.mexa64] Error 255

Also, if it is of any help, I'm attaching my Makefile.config here. 

Makefile.config:
===================================================================
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# USE_HDF5 := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment and set accordingly if you're using OpenCV 3/4
# OPENCV_VERSION := 3

# 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++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
MATLAB_DIR := /usr/local/MATLAB/R2020b/
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
# $(ANACONDA_HOME)/include/python2.7 \
# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @


===================================================================

I once again thank you for your time in answering this, and I hope this is the correct place to ask my doubt, or do you suggest me I should also post it on the github issues page?






rohit bharadwaj

unread,
Dec 3, 2020, 3:15:03 AM12/3/20
to Caffe Users
Sorry for the spam, but I managed to fix the above problem by changing the BLAS := open to BLAS := mkl. Now the make matcaffe worked fine, but in matlab when I try to use a code which is using caffe interface, Im getting this error. 


Invalid MEX-file '/home/rohit/Downloads/caffe-master/matlab/+caffe/private/caffe_.mexa64':
/usr/local/MATLAB/R2020b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found
(required by /home/rohit/Downloads/caffe-master/matlab/+caffe/private/caffe_.mexa64)

Should I try to build matcaffe again and check maybe?

rohit bharadwaj

unread,
Dec 3, 2020, 7:08:35 AM12/3/20
to Caffe Users
I think I fixed the above error as well by doing the following. Thank you so much for your time and help :)

Renaming the libstdc++.so.6 library file so that MATLAB cannot find it and is forced to use the system's version of the library. This file is located in matlabroot/sys/os/glnxa64 . Renaming it to libstdc++.so.6.old should suffice. (where "matlabroot" is root installation directory of MATLAB)

Reply all
Reply to author
Forward
0 new messages