ament / googletest

Google Test
BSD 3-Clause "New" or "Revised" License
3 stars 9 forks source link

Build with POSITION_INDEPENDENT_CODE #13

Closed cottsay closed 3 years ago

cottsay commented 3 years ago

This probably stems from a difference in the system linker scripts, but compiling packages against libgtest.a or libgmock.a can fail if they are built without -fPIC.

Should address build failures in consumers like this:

ld: gmock/libgmock.a(gtest-all.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
ld: gmock/libgmock.a(gmock-all.cc.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

As a 'weird' bug with a 'weird' solution that could have unintended side effects, I triggered a pretty wide build to test this change:

The motivation for this change is to unblock building rviz_default_plugins for RHEL 7.

Docs on this property: https://cmake.org/cmake/help/latest/prop_tgt/POSITION_INDEPENDENT_CODE.html