Repository: facebookarchive/caffe2

Issue #1980: Errors including std::__cxx11 or [abi:cxx11] or Linux with Anaconda
Created: 2018-02-16T23:36:58Z
This is an issue to track solutions and updates to these common errors encountered when installing Caffe2 with Anaconda on some Linux distros:
undefined reference to `google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string
undefined reference to `leveldb::Status::ToString[abi:cxx11]()
Undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]

These problems most commonly arise when using Anaconda's versions of protobuf, leveldb, or opencv.
These are all caused by this https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html . Basically, default Ubuntu ships with gcc 4.8.5 , but a lot of Anaconda libraries have been built with gcc 5+ . Libraries compiled with gcc > 5 are not compatible with those compiled with gcc < 5, due to changes in std::string and std::list; see the earlier link for details. What this means is that you must ensure that all of the libraries that Caffe2 is built against have the same ABI version, either all built with gcc < 5 or all built with gcc > 5.
If you encounter any of these errors that have [abi:cxx11] or std::__cxx11:: in them, then try one of the following options:

If you don't need to change Caffe2's source code, then just install our pre-built binary with conda install -c caffe2 caffe2 (or if you want CUDA, then conda install -c caffe2 caffe2-cuda9.0-cudnn7)

If you need to build from source:

Try adding -DCMAKE_CXX_FLAGS=-D__GLIBCXX_USE_CXX11_ABI=0 to your cmake call. If you are installing with conda-build, then your cmake call will be in either conda/cuda/build.sh conda/no_cuda/build.sh.
Use system versions of protobuf, opencv, or leveldb (try installing with apt-get). Uninstall these libraries from Anaconda and try to build again.
In both of these cases, remember to delete your build folder to remove any caching effects.

We will work on automatic detection of the gcc ABI version so that we can detect these problems and warn about them before they happen. A solution to allow seamless installs from source on Ubuntu machines with Anaconda packages may be very difficult, and we are open to suggestions.
UPDATE:
There are now gcc4.8 compatible conda packages available. You can install them like
conda install -c caffe2 caffe2-gcc4.8 or conda install -c caffe2-cuda9.0-cudnn7-gcc4.8
If you want to build Caffe2 from source but still want to use Anaconda and would like to avoid any gcc mismatch problems, then use https://github.com/caffe2/caffe2/blob/master/scripts/build_anaconda.sh , which can help adapt the conda-build process based on your gcc version.
For example, you can run
CONDA_INSTALL_LOCALLY=1 scripts/build_anaconda.sh
to build Caffe2 and install into the current conda environment or
CONDA_INSTALL_LOCALLY=1 BUILD_ENVIRONMENT=-cuda- scripts/build_anaconda.sh
to build Caffe2 with CUDA support and install into the current conda environment.

Duplicate issue #2096: ubuntu14.04: recipe for target ''[78%]:elementwise_op_gpu_test.cc:(.text+0x89): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'''
Created: 2018-03-01T07:30:03Z
System information
CMake version         : 3.5.1
--   CMake command         : /usr/bin/cmake
--   System                : unbuntu14.04
--   C++ compiler          : /usr/bin/c++
--   C++ compiler version  : 5.4.0
--   Protobuf compiler     : /usr/bin/protoc
--   Protobuf include path : /usr/include
--   Protobuf libraries    : optimized;/usr/lib/x86_64-linux-gnu/libprotobuf.so;debug;/usr/lib/x86_64-linux-gnu/libprotobuf.so;-pthread
--   BLAS                  : Eigen
--   CXX flags             :  -std=c++11 -O2 -fPIC -Wno-narrowing -Wno-invalid-partial-specialization
--   Build type            : Release
--   Compile definitions   :
--   BUILD_BINARY          : ON
--   BUILD_DOCS            : OFF
--   BUILD_PYTHON          : ON
--     Python version      : 2.7.13
--     Python library      : /data/xiaobing.wang/anaconda2/lib/libpython2.7.so
--   BUILD_SHARED_LIBS     : ON
--   BUILD_TEST            : ON
--   USE_CUDA              : ON
--     CUDA version        : 8.0
--     CuDNN version       : 5.1.10
--     CUDA root directory : /usr/local/cuda-8.0
--     CUDA library        : /usr/local/cuda-8.0/lib64/stubs/libcuda.so
--     CUDA NVRTC library  : /usr/local/cuda-8.0/lib64/libnvrtc.so
--     CUDA runtime library: /usr/local/cuda-8.0/lib64/libcudart.so
--     CUDA include path   : /usr/local/cuda-8.0/include
--     NVCC executable     : /usr/local/cuda-8.0/bin/nvcc
--     CUDA host compiler  : /usr/bin/cc
--     LevelDB version     : 1.18
--     Snappy version      : 1.1.3
--   USE_LITE_PROTO        : OFF
--   USE_LMDB              : ON
--     LMDB version        : 0.9.21
CMake summary output
[ 78%] Linking CXX executable ../bin/elementwise_op_gpu_test
/usr/bin/cmake: /data/xiaobing.wang/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)
/usr/bin/cmake: /data/xiaobing.wang/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)
/usr/bin/cmake: /data/xiaobing.wang/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)
/usr/bin/cmake: /data/xiaobing.wang/anaconda2/lib/libcrypto.so.1.0.0: no version information available (required by /usr/lib/x86_64-linux-gnu/libcurl.so.4)
CMakeFiles/elementwise_op_gpu_test.dir/operators/elementwise_op_gpu_test.cc.o: In function void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .isra.150]': elementwise_op_gpu_test.cc:(.text+0x89): undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_create(unsigned long&, unsigned long)'
CMakeFiles/elementwise_op_gpu_test.dir/operators/elementwise_op_gpu_test.cc.o: In function void caffe2::TypeMeta::_CopyNotAllowed<caffe2::Tensor<caffe2::CUDAContext> >(void const*, void*, unsigned long)': elementwise_op_gpu_test.cc:(.text._ZN6caffe28TypeMeta15_CopyNotAllowedINS_6TensorINS_11CUDAContextEEEEEvPKvPvm[_ZN6caffe28TypeMeta15_CopyNotAllowedINS_6TensorINS_11CUDAContextEEEEEvPKvPvm]+0x92): undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()'
CMakeFiles/elementwise_op_gpu_test.dir/operators/elementwise_op_gpu_test.cc.o: In function caffe2::OperatorBase::AddRelatedBlobInfo(caffe2::EnforceNotMet*)': elementwise_op_gpu_test.cc:(.text._ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE[_ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE]+0xda): undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::reserve(unsigned long)'
elementwise_op_gpu_test.cc:(.text._ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE[_ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE]+0x107): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)' elementwise_op_gpu_test.cc:(.text._ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE[_ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE]+0x117): undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_append(char const*, unsigned long)'
elementwise_op_gpu_test.cc:(.text._ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE[_ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE]+0x217): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)' elementwise_op_gpu_test.cc:(.text._ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE[_ZN6caffe212OperatorBase18AddRelatedBlobInfoEPNS_13EnforceNotMetE]+0x244): undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_append(char const*, unsigned long)'
elementwise_op_gpu_test.cc:21'
../lib/libcaffe2_gpu.so: undefined reference to std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())@GLIBCXX_3.4.21' ../lib/libcaffe2.so: undefined reference to std::thread::_M_start_thread(std::shared_ptrstd::thread::_Impl_base, void ()())'
../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*)@GLIBCXX_3.4.21' ../lib/libcaffe2.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_construct(unsigned long, char)'
../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::end()@GLIBCXX_3.4.21' ../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21'
/usr/lib/x86_64-linux-gnu/libglog.so: undefined reference to std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(char*, unsigned long, unsigned long)@GLIBCXX_3.4.21' /usr/lib/x86_64-linux-gnu/libprotobuf.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::find_first_of(char const, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
....
...
....
...
...
...
../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long) const@GLIBCXX_3.4.21' ../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::swap(std::__cxx11::basic_string<char, std::char_traits, std::allocator >&)@GLIBCXX_3.4.21'
../lib/libcaffe2.so: undefined reference to __cxa_throw_bad_array_new_length' ../lib/libcaffe2_gpu.so: undefined reference to vtable for std::__cxx11::basic_stringbuf<char, std::char_traits, std::allocator >@GLIBCXX_3.4.21'
../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_set_length(unsigned long)@GLIBCXX_3.4.21' ../lib/libcaffe2_gpu.so: undefined reference to std::__cxx11::basic_stringbuf<char, std::char_traits, std::allocator >::str() const@GLIBCXX_3.4.21'
collect2: error: ld returned 1 exit status
caffe2/CMakeFiles/elementwise_op_gpu_test.dir/build.make:124: recipe for target 'bin/elementwise_op_gpu_test' failed
make[3]: *** [bin/elementwise_op_gpu_test] Error 1
make[3]: Leaving directory '/data/xiaobing.wang/pingjun.li/caffe2-new/build'
CMakeFiles/Makefile2:1207: recipe for target 'caffe2/CMakeFiles/elementwise_op_gpu_test.dir/all' failed
make[2]: *** [caffe2/CMakeFiles/elementwise_op_gpu_test.dir/all] Error 2
make[2]: Leaving directory '/data/xiaobing.wang/pingjun.li/caffe2-new/build'
Makefile:138: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/data/xiaobing.wang/pingjun.li/caffe2-new/build'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
******** Summary ********
I don't know

Closing comment (2018-03-02T16:00:27Z): This is a duplicate of #1980 . Please read that discussion