google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
6.99k stars 2.05k forks source link

building phase in Ubuntu 23.10 : /usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPI #1024

Closed raphael10-collab closed 8 months ago

raphael10-collab commented 8 months ago

I tried to compile and build glog library in Ubuntu 23.10 but in the building phase I get some errors:

raphy@raohy:~$ git clone https://github.com/google/glog.git
Cloning into 'glog'...
remote: Enumerating objects: 4600, done.
remote: Counting objects: 100% (2265/2265), done.
remote: Compressing objects: 100% (334/334), done.
remote: Total 4600 (delta 2074), reused 2021 (delta 1930), pack-reused 2335
Receiving objects: 100% (4600/4600), 2.39 MiB | 14.95 MiB/s, done.
Resolving deltas: 100% (3260/3260), done.

 raphy@raohy:~$ cd glog/

raphy@raohy:~/glog$ cmake -S . -B build -G "Unix Makefiles"
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find GTest (missing: GTest_DIR)
-- Looking for gflags namespace
-- Looking for gflags namespace - gflags
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found Unwind: /usr/include/x86_64-linux-gnu (found version "1.6.2") 
-- Looking for _Unwind_Backtrace
-- Looking for _Unwind_Backtrace - found
-- Looking for _Unwind_GetIP
-- Looking for _Unwind_GetIP - found
-- Looking for unw_get_reg
-- Looking for unw_get_reg - found
-- Looking for unw_getcontext
-- Looking for unw_getcontext - found
-- Looking for unw_init_local
-- Looking for unw_init_local - found
-- Looking for unw_step
-- Looking for unw_step - found
-- Looking for C++ include dlfcn.h
-- Looking for C++ include dlfcn.h - found
-- Looking for C++ include glob.h
-- Looking for C++ include glob.h - found
-- Looking for C++ include pwd.h
-- Looking for C++ include pwd.h - found
-- Looking for C++ include sys/syscall.h
-- Looking for C++ include sys/syscall.h - found
-- Looking for C++ include sys/time.h
-- Looking for C++ include sys/time.h - found
-- Looking for C++ include sys/types.h
-- Looking for C++ include sys/types.h - found
-- Looking for C++ include sys/utsname.h
-- Looking for C++ include sys/utsname.h - found
-- Looking for C++ include sys/wait.h
-- Looking for C++ include sys/wait.h - found
-- Looking for C++ include syscall.h
-- Looking for C++ include syscall.h - found
-- Looking for C++ include syslog.h
-- Looking for C++ include syslog.h - found
-- Looking for C++ include ucontext.h
-- Looking for C++ include ucontext.h - found
-- Looking for C++ include unistd.h
-- Looking for C++ include unistd.h - found
-- Looking for C++ include stdint.h
-- Looking for C++ include stdint.h - found
-- Looking for C++ include stddef.h
-- Looking for C++ include stddef.h - found
-- Check size of mode_t
-- Check size of mode_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Looking for dladdr
-- Looking for dladdr - found
-- Looking for fcntl
-- Looking for fcntl - found
-- Looking for pread
-- Looking for pread - found
-- Looking for pwrite
-- Looking for pwrite - found
-- Looking for sigaction
-- Looking for sigaction - found
-- Looking for sigaltstack
-- Looking for sigaltstack - found
-- Looking for backtrace
-- Looking for backtrace - found
-- Looking for backtrace_symbols
-- Looking for backtrace_symbols - found
-- Looking for _chsize_s
-- Looking for _chsize_s - not found
-- Looking for UnDecorateSymbolName
-- Looking for UnDecorateSymbolName - not found
-- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP
-- Performing Test HAVE___SYNC_VAL_COMPARE_AND_SWAP - Success
-- Looking for abi::__cxa_demangle
-- Looking for abi::__cxa_demangle - found
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_PC
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_PC - Failed
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_EIP
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_EIP - Failed
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_RIP
-- Performing Test HAVE_PC_FROM_UCONTEXT_uc_mcontext_gregs_REG_RIP - Success
-- Looking for __ELF__
-- Looking for __ELF__ - found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done (2.8s)
-- Generating done (0.0s)
-- Build files have been written to: /home/raphy/glog/build

raphy@raohy:~/glog$ cmake --build build
[  2%] Copying find modules...
[  5%] Building CXX object CMakeFiles/glog_internal.dir/src/demangle.cc.o
[  8%] Building CXX object CMakeFiles/glog_internal.dir/src/logging.cc.o
[ 10%] Building CXX object CMakeFiles/glog_internal.dir/src/raw_logging.cc.o
[ 13%] Building CXX object CMakeFiles/glog_internal.dir/src/signalhandler.cc.o
[ 16%] Building CXX object CMakeFiles/glog_internal.dir/src/symbolize.cc.o
[ 18%] Building CXX object CMakeFiles/glog_internal.dir/src/utilities.cc.o
[ 21%] Building CXX object CMakeFiles/glog_internal.dir/src/vlog_is_on.cc.o
[ 21%] Built target glog_internal
[ 24%] Generating CMakeFiles/glog.cc
[ 27%] Building CXX object CMakeFiles/glog.dir/CMakeFiles/glog.cc.o
[ 29%] Linking CXX shared library libglog.so
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_completions.cc.o): warning: relocation against `_ZN3fLS25FLAGS_tab_completion_wordB5cxx11E' in read-only section `.text.startup'
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' 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
gmake[2]: *** [CMakeFiles/glog.dir/build.make:117: libglog.so.0.7.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:893: CMakeFiles/glog.dir/all] Error 2
gmake: *** [Makefile:166: all] Error 2
raphy@raohy:~/glog$ 

How to make it work?

sergiud commented 8 months ago

Please use the search function before submitting an issue. This has been discussed many times before: https://github.com/google/glog/issues/983#issuecomment-1845345695.

raphael10-collab commented 8 months ago

Thank you for referencing the other github's issue

Since this issue has been discussed many times before, I would suggest to include in the README file this indication:

first compiled and built `gflags` library (https://github.com/gflags/gflags) with `-DBUILD_SHARED_LIBS=ON` flag: ```cmake -DBUILD_SHARED_LIBS=ON -B build ``` 
sergiud commented 8 months ago

This is a gflags not a glog issue that should be discussed in the corresponding project.