cmake目标链接openssl错误

时间:2018-05-22 06:11:02

标签: c++ cmake openssl

以下是我CMakeLists.txt的一部分。

find_package(OpenSSL REQUIRED)

add_executable(
        aes_test
        src/aes_test.cpp
)

MESSAGE(${OPENSSL_FOUND})
MESSAGE(${OPENSSL_SSL_LIBRARY})

target_link_libraries(
        aes_test
        ${OPENSSL_SSL_LIBRARY}
)

MESSAGE的输出

TRUE
/usr/local/opt/openssl/lib/libssl.dylib

cmake找到OpenSSL但是当我将程序aes_test与OpenSSL关联时,会出现链接错误。

Undefined symbols for architecture x86_64:
  "_AES_decrypt", referenced from:
      _main in aes_test.cpp.o
  "_AES_encrypt", referenced from:
      _main in aes_test.cpp.o
  "_AES_set_decrypt_key", referenced from:
      _main in aes_test.cpp.o
  "_AES_set_encrypt_key", referenced from:
      _main in aes_test.cpp.o
ld: symbol(s) not found for architecture x86_64

aes_test.cpp中,我使用AES_set_encrypt_key中定义的函数aes.h。怎么了 ?谁能帮我?提前谢谢。

1 个答案:

答案 0 :(得分:0)

target_link_libraries(
        aes_test
        ssl
        crypto
)

以上代码适用于我。