'Getting undefined reference to `EVP_PKEY_get_size' & undefined reference to `EVP_PKEY_CTX_set_rsa_keygen_bits'

I am getting these kind of linker errors :

/usr/bin/ld: ../../lib/src/util/cryptolib/libcrypto_unit.so.1.0.1: undefined reference to `EVP_PKEY_get_size'
/usr/bin/ld: ../../lib/src/util/cryptolib/libcrypto_unit.so.1.0.1: undefined reference to `EVP_PKEY_CTX_set_rsa_keygen_bits'
collect2: error: ld returned 1 exit status
make[3]: *** [bin/client/CMakeFiles/client.dir/build.make:166: bin/client/client] Error 1
make[2]: *** [CMakeFiles/Makefile2:437: bin/client/CMakeFiles/client.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:444: bin/client/CMakeFiles/client.dir/rule] Error 2
make: *** [Makefile:177: client] Error 2

My crpyto_unit.h library is dynamically linked to client core.

CMakeLists.txt of *crpyto_unit*

cmake_minimum_required(VERSION 3.9)
project(crypto_unit VERSION 1.0.1 DESCRIPTION "crypto_unit description")
include(GNUInstallDirs)

add_library(crypto_unit SHARED crypto_unit.cpp)

set_target_properties(crypto_unit PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION 1
    PUBLIC_HEADER api/crypto_unit.h)
    
SET(GCC_COVERAGE_LINK_FLAGS    "-lssl" "-lcrypto")
configure_file(crypto_unit.pc.in crypto_unit.pc @ONLY)
target_include_directories(crypto_unit PRIVATE .)
install(TARGETS crypto_unit
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} OpenSSL::Crypto)

install(FILES ${CMAKE_BINARY_DIR}/crypto_unit.pc
    DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
    

CMakeLists.txt of *client*

cmake_minimum_required(VERSION 2.8.9)
project (client)


set (CMAKE_BINARY_DIR "./../../bin/client/")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_CXX_FLAGS "-g -w -O2 -pthread")

include_directories(../include)
include_directories(../../lib/include)

add_executable(client src/main.cpp
                        src/client.cpp
                           src/communication_unit.cpp
                                src/connection_handler.cpp
                                    src/io_unit.cpp
                                        src/handler.cpp)

target_link_libraries( client debug_helper)
target_link_libraries( client message_model)
target_link_libraries( client message_resolver)
target_link_libraries( client crypto_unit)

I still don't use any methods from crypto_unit. Just trying to complete compilation.

If it's necessary I can provide according source files.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source