gflags: undefined reference to 'FlagRegisterer::FlagRegisterer'
I installed gflags first, and then failed to install glog.
src/logging_unittest-logging_unittest.o: In function '__static_initialization_and_destruction_0': /opt/packages/glog-0.3.4/src/googletest.h:93: undefined reference to '::FlagRegisterer::FlagRegisterer<std::string>(char const*, char const*, char const*, std::string*, std::string*)'
/opt/packages/glog-0.3.4/src/googletest.h:94: undefined reference to 'google::FlagRegisterer::FlagRegisterer<std::string>(char const*, char const*, char const*, std::string*, std::string*)'
/opt/packages/glog-0.3.4/src/googletest.h:96: undefined reference to 'google::FlagRegisterer::FlagRegisterer<bool>(char const*, char const*, char const*, bool*, bool*)'
/opt/packages/glog-0.3.4/src/googletest.h:100: undefined reference to 'google::FlagRegisterer::FlagRegisterer<int>(char const*, char const*, char const*, int*, int*)'
collect2: error: ld returned 1 exit status
make: *** [logging_unittest] Error 1
So, I removed all libs of gflags and reinstall the glog, it worked at that time. But, when I installed folly, it prompted a similar error. How to fix it? Who can help me?
make all-recursive
make[1]: Entering directory '/opt/packages/folly/folly'
Making all in .
make[2]: Entering directory '/opt/packages/folly/folly'
/bin/bash ./libtool --tag=CXX --mode=link g++ -std=gnu++0x -g -O2 -lboost_context -lboost_thread -lboost_filesystem -lboost_system -lboost_regex -lpthread -L/usr/local/include/double-conversion/ -o generate_fingerprint_tables build/GenerateFingerprintTables.o libfollybase.la -llzma -lz -lsnappy -llz4 -liberty -ljemalloc -levent -ldouble-conversion -lssl -lgflags -lglog
libtool: link: g++ -std=gnu++0x -g -O2 -o generate_fingerprint_tables build/GenerateFingerprintTables.o -L/usr/local/include/double-conversion/ ./.libs/libfollybase.a -lboost_context -lboost_thread -lboost_filesystem -lboost_system -lboost_regex -lpthread -llzma -lz -lsnappy -llz4 -liberty -ljemalloc -levent -ldouble-conversion -lssl -lgflags -lglog
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libglog.so: undefined reference to 'google::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, char const*, void*, void*)'
collect2: error: ld returned 1 exit status
make[2]: *** [generate_fingerprint_tables] Error 1
make[2]: Leaving directory '/opt/packages/folly/folly'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/opt/packages/folly/folly'
make: *** [all] Error 2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (6 by maintainers)
I saw so many doc,but could not find a solution.WTF.
I have the same problem and this is my fix:
With gflags complied to shared lib and LDFLAGS set, it’s works on my ubuntu.
Some notes to help resolve these undefined reference issues:
The “solution” of uninstalling
curlcannot be a real fix. Don’t.Regarding the original report from Jan 2017:
FlagRegistererconstructor was changed in Jul 2017 to a template function.The default namespace of both gflags and glog libraries is
google.GFLAGS_NAMESPACEwas modified, the namespace should be fine.When building the gflags library on macOS 10.12 with clang:
All expected explicit template instantiations of the
FlagRegistererconstructor are present:When using the GCC 7.2 compiler installed using Homebrew, the symbol for
std::stringdiffers:Note the
std::__cxx11::basic_stringinstead ofstd::__1::basic_string.This SO question may provide insight as to how to resolve linker error of undefined reference to
google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string[...].If you build with GCC >=5.1 and see many undefined reference to
google::FlagRegisterer::FlagRegisterererrors, not only forstd::__cxx11::basic_string, you are probably trying to link with a gflags library that was built with a different compiler, e.g., clang. I could confirm this on macOS 10.12, where I had/usr/local/lib/libgflags.abuilt with clang still installed. Removing it and linking with thelibgflags.alibrary built with the same GCC version then gave only one error:Still using GCC 7.2, building both gflags and glog with
CMAKE_CXX_FLAGS="-std=c++17 -D _GLIBCXX_USE_CXX11_ABI=0", we get the following output ofnm | c++filt:But the linker error when building glog reads:
Note that in
nmoutput it isstd::stringwhereas the linker error refers tostd::basic_string. This error persists for either setting of_GLIBCXX_USE_CXX11_ABI=0|1.Note that using GCC 4.9 (before ABI change), linking glog with gflags library succeeds. Given that the built also works without issues with clang, it seems changes in GCC are responsible for the undefined reference issues.
To be continued…
If anybody face this problem, just uninstall
curland make sure there’s nolibcurlfiles left in your/usr/local/lib😉 That fixed it for meEdited by @schuhschuh:
curlhas nothing to do with gflags and/or glog. Read on.Hi I encounter the similar problem. Have you fixed this problem? What is the solution? My environment is : Ubuntu 14.04 LTS, cmake 3.2.2 gflags: latest version from Github master, installed using
glog: release 0.3.5, installed using
I didn’t set the namespace of these two lib explicitly. I encountered similar error during building glog:
undefined reference to google::FlagRegisterer::FlagRegistererBut after I clean everything and re-build gflags and flog, passsed. Then I tried to build Google-Cartographer, failed again.Is the error of making Cartographer caused by gflags and glog?
I was also not being able to compile
glogfrom source and I was getting the same error.In my case the culprit was
/usr/lib/x86_64-linux-gnu/libgflags.a. It was in the system even aftersudo apt-get purge libgflags-dev.Sequence of commands I used to install
protobuf,gflagsandglogfrom source:IT WAS BECAUSE TWO
libgflags_nothreads.aCONFLICTS.REMOVE ONE OF THEM !!!
which is usually installed in your local host’s /usr dir.