Make error due to undefined references with google namespaces

8,387 views
Skip to first unread message

Shikhar Sharma

unread,
Sep 9, 2015, 6:44:33 PM9/9/15
to Caffe Users
I downloaded the current GitHub Caffe repo. In the build directory I used:

cmake -D GFLAGS_INCLUDE_DIR=/pkgs/gflags/include -D GLOG_INCLUDE_DIR=/pkgs/glog-0.3.3/include -D LMDB_INCLUDE_DIR=/u/shikhar/research/latest-environment/lmdb/libraries/liblmdb/ -D CUDA_ARCH_NAME=Kepler ..

Cmake works fine and finds the required libraries. I am attaching the output which you can ignore:

-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.54.0
-- Found the following Boost libraries:
--   system
--   thread
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found GFlags: /pkgs/gflags/include  
-- Found gflags  (include: /pkgs/gflags/include, library: /usr/local/lib/libgflags.a)
-- Found Glog: /pkgs/glog-0.3.3/include  
-- Found glog    (include: /pkgs/glog-0.3.3/include, library: /usr/local/lib/libglog.so)
-- Found PROTOBUF: /usr/lib/x86_64-linux-gnu/libprotobuf.so  
-- Found PROTOBUF Compiler: /usr/bin/protoc
-- Found HDF5: /usr/lib/x86_64-linux-gnu/libhdf5_hl.so;/usr/lib/x86_64-linux-gnu/libhdf5.so  
-- Found LMDB: /u/shikhar/research/latest-environment/lmdb/libraries/liblmdb  
-- Found lmdb    (include: /u/shikhar/research/latest-environment/lmdb/libraries/liblmdb, library: /usr/local/lib/liblmdb.so)
-- Found LevelDB: /usr/include  
-- Found LevelDB (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libleveldb.so)
-- Found Snappy: /usr/include  
-- Found Snappy  (include: /usr/include, library: /usr/lib/libsnappy.so)
-- CUDA detected: 6.5
-- Found cuDNN (include: /pkgs/cuda-6.5/include, library: /pkgs/cuda-6.5/lib64/libcudnn.so)
-- Added CUDA NVCC flags for: sm_30 sm_35
-- OpenCV found (/usr/share/OpenCV)
-- Found Atlas: /usr/include  
-- Found Atlas (include: /usr/include, library: /usr/lib/libatlas.so)
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable version "2.7.6", minimum required is "2.7")
-- Found NumPy: /usr/local/lib/python2.7/dist-packages/numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/core/include (found suitable version "1.9.2", minimum required is "1.7.1")
-- NumPy ver. 1.9.2 found (include: /usr/local/lib/python2.7/dist-packages/numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/core/include)
-- Boost version: 1.54.0
-- Found the following Boost libraries:
--   python
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.6")
-- Detected Doxygen OUTPUT_DIRECTORY: ./doxygen/
-- Found Git: /usr/bin/git (found version "1.9.1")
--
-- ******************* Caffe Configuration Summary *******************
-- General:
--   Version           :   <TODO> (Caffe doesn't declare its version in headers)
--   Git               :   rc2-526-g5367a1a-dirty
--   System            :   Linux
--   C++ compiler      :   /usr/bin/c++
--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release
--
--   BUILD_SHARED_LIBS :   ON
--   BUILD_python      :   ON
--   BUILD_matlab      :   OFF
--   BUILD_docs        :   ON
--   CPU_ONLY          :   OFF
--
-- Dependencies:
--   BLAS              :   Yes (Atlas)
--   Boost             :   Yes (ver. 1.54)
--   glog              :   Yes
--   gflags            :   Yes
--   protobuf          :   Yes (ver. 2.5.0)
--   lmdb              :   Yes (ver. 0.9.16)
--   Snappy            :   Yes (ver. 1.1.0)
--   LevelDB           :   Yes (ver. 1.15)
--   OpenCV            :   Yes (ver. 2.4.8)
--   CUDA              :   Yes (ver. 6.5)
--
-- NVIDIA CUDA:
--   Target GPU(s)     :   Kepler
--   GPU arch(s)       :   sm_30 sm_35
--   cuDNN             :   Yes
--
-- Python:
--   Interpreter       :   /usr/bin/python2.7 (ver. 2.7.6)
--   Libraries         :   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
--   NumPy             :   /usr/local/lib/python2.7/dist-packages/numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/core/include (ver 1.9.2)
--
-- Documentaion:
--   Doxygen           :   /usr/bin/doxygen (1.8.6)
--   config_file       :   /u/shikhar/research/latest-environment/bvlc-caffe/.Doxyfile
--
-- Install:
--   Install path      :   /u/shikhar/research/latest-environment/bvlc-caffe/build/install
--
-- Configuring done
-- Generating done
-- Build files have been written to: /u/shikhar/research/latest-environment/bvlc-caffe/build

make however always fails with:

[ 89%] Building CXX object tools/CMakeFiles/caffe.bin.dir/caffe.cpp.o
Linking CXX executable caffe
CMakeFiles/caffe.bin.dir/caffe.cpp.o: In function `main':
caffe.cpp:(.text.startup+0x3e): undefined reference to `
google::SetUsageMessage(std::string const&)'
caffe.cpp:(.text.startup+0x7b): undefined reference to `google::ShowUsageWithFlagsRestrict(char const*, char const*)'

CMakeFiles/caffe.bin.dir/caffe.cpp.o: In function `_GLOBAL__sub_I_caffe.cpp':
caffe.cpp:(.text.startup+0x38f): undefined reference to `
google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
caffe.cpp:(.text.startup+0x40d): undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'

caffe
.cpp:(.text.startup+0x48b): undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
caffe.cpp:(.text.startup+0x509): undefined reference to `
google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
caffe.cpp:(.text.startup+0x587): undefined reference to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'

CMakeFiles/caffe.bin.dir/caffe.cpp.o:caffe.cpp:(.text.startup+0x5d2): more undefined references to `google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)' follow
../lib/libcaffe.so: undefined reference to `
google::ParseCommandLineFlags(int*, char***, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/caffe] Error 1
make[1]: *** [tools/CMakeFiles/caffe.bin.dir/all] Error 2
make: *** [all] Error 2

All libraries seem to be found. Adding #include <gflags/gflags.h> to caffe.cpp and common.cpp does not help as suggested in one GitHub issue. Any ideas how to make this work? What's the reason behind these errors?
Thanks in advance.

Darren Garvey

unread,
Sep 9, 2015, 6:59:50 PM9/9/15
to Shikhar Sharma, Caffe Users
Hi Shikhar,

What distribution are you on? Also what linker are you using?

I had a problem for a couple of weeks with the gold linker as it appeared to be dropping transitive library dependencies (this appears to be fixed now as I'm using gold (1.11 on Ubuntu 15.04) now without issue. I also had an issue with the bdf linker (GNU ld) as at least on Ubuntu visibility hidden became the default. Again I'd made a change to change the visibility, ie. setting "-fvisibility=default", but I no longer need that patch.

What is the output of:

nm -C /usr/local/lib/libgflags.a | grep FlagRegisterer

? My libgflags.a is in a different location (/usr/lib/x86_64-linux-gnu/libgflags.a) but does contain the symbols yours is missing. Also "make VERBOSE=1" will give you the exact linker command which should give you some clues what libraries are being included.

Also be sure the installed gflags matches the headers that are being used for compilation. The location of your package seems a bit strange to me, but I assume you're building it yourself:


Found gflags  (include: /pkgs/gflags/include, library: /usr/local/lib/libgflags.a)

Cheers,
Darren

--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/a5b1ba66-92cb-4ea9-b774-af7fbdfa76b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shikhar Sharma

unread,
Sep 10, 2015, 11:33:35 AM9/10/15
to Caffe Users, shik...@gmail.com
Hi Darren

You were right about the include and library being different. I hadn't even noticed that.
Found gflags  (include: /pkgs/gflags/include, library:/usr/local/lib/libgflags.a)
gflags located the system library first and that was causing the problem. The same thing was happening with lmdb and glog. The system had libraries installed but not the includes.

I was able to fix those by manually specifying the library:
cmake -D GFLAGS_INCLUDE_DIR=/pkgs/gflags/include -D GFLAGS_LIBRARY=/pkgs/gflags/lib/libgflags.a -D GLOG_INCLUDE_DIR=/pkgs/glog-0.3.3/include -D GLOG_LIBRARY=/pkgs/glog-0.3.3/lib/libglog.so -D LMDB_INCLUDE_DIR=/u/shikhar/research/latest-environment/lmdb/libraries/liblmdb/ -D LMDB_LIBRARIES=/u/shikhar/research/latest-environment/lmdb/libraries/liblmdb/liblmdb.so -D CUDA_ARCH_NAME=Kepler ..

That worked. Thanks for all the help. Caffe installation is complete now.

Cheers
Shikhar
Reply all
Reply to author
Forward
0 new messages