I'm trying to build a shared library (Aeron media driver) and I need to have one of its dependency linked statically (libbsd.a).
I have updated the original CMakeLists.txt in order to have this in the following way :
add_library(libbsd STATIC IMPORTED)
set_target_properties(libbsd PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libbsd.a)
set_target_properties(libbsd PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES /usr/include)
target_link_libraries(
aeron_driver
${CMAKE_DL_LIBS}
libbsd
${AERON_LIB_UUID_LIBS}
${AERON_LIB_M_LIBS}
${AERON_LIB_ATOMIC_LIBS}
${CMAKE_THREAD_LIBS_INIT}
${AERON_LIB_WINSOCK_LIBS})
Unfortunaly CMake output this error :
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libbsd.a(getentropy.o): relocation R_X86_64_PC32 against symbol `getentropy' 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
I have tried several ways of setting the option but no ones work
For instance:
target_compile_options(libbsd INTERFACE -fPIC)
still lead to the same error.
How to properly set this compiler flag ? Do I have to set this option on the aeron_driver target or on libbsd target ?