Caffe: Issues with compiling caffe with python, undefined reference to `std::__cxx11::…'

Created on 4 Nov 2016  Â·  5Comments  Â·  Source: BVLC/caffe

Issue summary

I used to compile successfully caffe with WITH_PYTHON_LAYER:=1 on Ubuntu 14.04. Then I switched to Ubuntu 16.04, using the same settings but different built-in software such as g++ 5.4 for 16.04 instead of g++ 4.8 for 14.04, I failed to compile caffe with python. Would you please give me some advice on this issue?

Steps to reproduce

System configuration

Operating system: Unbuntu 16.04
Compiler: g++ 5.4.0
CUDA version (if applicable): cuda-8.0
CUDNN version (if applicable): none
BLAS: openBlas
Python or MATLAB version (for pycaffe and matcaffe respectively): Python

Error Message

The following is part of the error message I got

.build_release/lib/libcaffe.so: undefined reference to google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))' //usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22: undefined reference tostd::__cxx11::basic_stringstream, std::allocator >::basic_stringstream(std::_Ios_Openmode)@GLIBCXX_3.4.21'
.build_release/lib/libcaffe.so: undefined reference to leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference tostd::__cxx11::basic_string, std::allocator >::append(char const)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const@GLIBCXX_3.4.21' //usr/lib/x86_64-linux-gnu/libtbb.so.2: undefined reference tostd::runtime_error::runtime_error(std::__cxx11::basic_string, std::allocator > const&)@GLIBCXX_3.4.21'
.build_release/lib/libcaffe.so: undefined reference to cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference tovtable for std::__cxx11::basic_ostringstream, std::allocator >@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)@GLIBCXX_3.4.21' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libleveldb.so: undefined reference to__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
.build_release/lib/libcaffe.so: undefined reference to google::protobuf::internal::StringTypeHandlerBase::New()' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_python.so: undefined reference tostd::invalid_argument::invalid_argument(std::__cxx11::basic_string, std::allocator > const&)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_thread.so: undefined reference to std::__cxx11::numpunct<char> const& std::use_facet<std::__cxx11::numpunct<char> >(std::locale const&)@GLIBCXX_3.4.21' .build_release/lib/libcaffe.so: undefined reference togoogle::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream
)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_thread.so: undefined reference to std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference toVTT for std::__cxx11::basic_ostringstream, std::allocator >@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_python.so: undefined reference to std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_M_construct(unsigned long, wchar_t)@GLIBCXX_3.4.21' //usr/lib/x86_64-linux-gnu/libtbb.so.2: undefined reference tostd::out_of_range::out_of_range(std::__cxx11::basic_string, std::allocator > const&)@GLIBCXX_3.4.21'
.build_release/lib/libcaffe.so: undefined reference to leveldb::Status::ToString() const' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference tostd::__cxx11::basic_string, std::allocator >::compare(std::__cxx11::basic_string, std::allocator > const&) const@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21' .build_release/lib/libcaffe.so: undefined reference togoogle::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream)'
collect2: error: ld returned 1 exit status
Makefile:619: recipe for target '.build_release/tools/convert_imageset.bin' failed
make: *
* [.build_release/tools/convert_imageset.bin] Error 1

Most helpful comment

If the cmake build still has issues, try adding this:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

It looks like you may have some libraries compiled against an older version of gcc, which means you need to throw this compatibility flag.

All 5 comments

Try to use CMake build instead of Makefile.config.
make clean and follow CMake Build Instruction.

If the cmake build still has issues, try adding this:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

It looks like you may have some libraries compiled against an older version of gcc, which means you need to throw this compatibility flag.

@abuccts Thanks. Problem solved.

@JakeRenn please close this issue, since it has been solved.

I am running against make command but not cmake, appending -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 to the FLAGS in Makefile fixes the problem.

# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS) -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0
# mex may invoke an older gcc that is too liberal with -Wuninitalized
MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0

Was this page helpful?
0 / 5 - 0 ratings