Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JakeRenn opened this issue Nov 4, 2016 · 5 comments

Comments

@JakeRenn
Copy link

JakeRenn commented Nov 4, 2016

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 to std::__cxx11::basic_stringstream<char, std::char_traits, 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 to std::__cxx11::basic_string<char, std::char_traits, 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 to std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits, 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 to vtable for std::__cxx11::basic_ostringstream<char, std::char_traits, 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 to std::invalid_argument::invalid_argument(std::__cxx11::basic_string<char, std::char_traits, 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 to google::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 to VTT for std::__cxx11::basic_ostringstream<char, std::char_traits, 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 to std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits, 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 to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::compare(std::__cxx11::basic_string<char, std::char_traits, 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 to google::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

@abuccts
Copy link

abuccts commented Nov 4, 2016

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

@dtmoodie
Copy link

dtmoodie commented Nov 4, 2016

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.

@JakeRenn
Copy link
Author

JakeRenn commented Nov 8, 2016

@abuccts Thanks. Problem solved.

@williford
Copy link
Contributor

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

@hailiang-wang
Copy link

hailiang-wang commented Jun 26, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants