make error
When I make, there are some errors. And I cannot fix it.
Scanning dependencies of target glog
[ 4%] Building CXX object CMakeFiles/glog.dir/src/demangle.cc.o
[ 9%] Building CXX object CMakeFiles/glog.dir/src/logging.cc.o
[ 13%] Building CXX object CMakeFiles/glog.dir/src/raw_logging.cc.o
[ 18%] Building CXX object CMakeFiles/glog.dir/src/symbolize.cc.o
[ 22%] Building CXX object CMakeFiles/glog.dir/src/utilities.cc.o
[ 27%] Building CXX object CMakeFiles/glog.dir/src/vlog_is_on.cc.o
[ 31%] Building CXX object CMakeFiles/glog.dir/src/signalhandler.cc.o
[ 36%] Linking CXX shared library libglog.so
/usr/bin/ld: /usr/local/lib/libgflags_nothreads.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `_ZN22gflags_mutex_namespace5MutexD1Ev' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
CMakeFiles/glog.dir/build.make:251: recipe for target 'libglog.so.0.5.0' failed
make[2]: *** [libglog.so.0.5.0] Error 1
CMakeFiles/Makefile2:1062: recipe for target 'CMakeFiles/glog.dir/all' failed
make[1]: *** [CMakeFiles/glog.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
cd gflog mkdir bulid cd bulid cmake .. make
The error concerns gflags and the error message says what needs to be done:
_ZN22gflags_mutex_namespace5MutexD1Ev' can not be used when making a shared object; recompile with -fPIC
Hi ,
I got the same error message. Do you know how to fix it? Thanks!
_ZN22gflags_mutex_namespace5MutexD1Ev' can not be used when making a shared object; recompile with -fPIC
Here is my comment to make gflags and glog `git clone https://github.com/gflags/gflags.git cd gflags mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/home/mwp141/Tool/gflags-2.2 make make install
git clone https://github.com/google/glog.git export LDFLAGS='-L/home/mwp141/Tool/gflags-2.2/lib' gflags --version cd glog mkdir build cd build #CXXFLAGS="-fPIC" cmake -DCMAKE_INSTALL_PREFIX=/home/mwp141/Tool/glog-build cmake .. -DCMAKE_INSTALL_PREFIX=/home/mwp141/Tool/glog-build -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_LIB=ON make make install`
You need to compile gflags with the -fPIC flag as the error message suggests.
@sergiud How exactly should i do this ?
If you encounter the issue with log like /usr/bin/ld: /path/to/libgflags_nothreads.a(gflags.cc.o), try to rebuild gflags with -DBUILD_SHARED_LIBS=ON to get a shared library libgflags.so instead of the static one.
This link problem does NOT mainly result from glog repo, since glog already added -fPIC support in CMakeLists.txt here.
You need to compile gflags with the
-fPICflag as the error message suggests.
Sincere thanks! I had misunderstood the error message. I recompiled my program many times rather than 'gflags' so it never worked..