I want to statically link the libraries listed below:
set_target_properties(exec PROPERTIES LINK_SEARCH_START_STATIC 1)
set_target_properties(exec PROPERTIES LINK_SEARCH_END_STATIC 1)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_library(SODIUM_LIB libsodium.a REQUIRED)
find_library(SSL_LIB libssl.a REQUIRED)
find_library(CRYPTO_LIB libcrypto.a REQUIRED)
find_library(DL_LIB libdl.a REQUIRED)
message(${SODIUM_LIB})
message(${SSL_LIB})
message(${CRYPTO_LIB})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
target_link_libraries(
exec
${SODIUM_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${DL_LIB}
I do not want to add -static
to CMAKE_EXE_LINKER_FLAGS
, because in that case everything is linked static. CMake finds the static libraries:
/usr/local/lib/libsodium.a
/usr/lib/x86_64-linux-gnu/libssl.a
/usr/lib/x86_64-linux-gnu/libcrypto.a
and it seems that everything is linked statically except libcrypto
:
readelf -d exec
0x0000000000000001 (NEEDED) Shared library: [libcrypto.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
How can I link libcrypto
statically to my executable?