cmake 构建mysql-connector-c++ example时链接器链接openssl头失败

ffx8fchx  于 2023-03-23  发布在  Mysql
关注(0)|答案(1)|浏览(145)

我正在尝试构建一个使用mysql-connector-c++ 1.1.13的应用程序。
我遇到的问题是,链接器似乎无法链接/找到一些标题,但我不知道为什么。我看过mysql-connector-c++1 docs,多个stackoverflow和github帖子/线程,但找不到任何帮助。
我得到的错误是:

Undefined symbols for architecture x86_64:
  "_EVP_CIPHER_block_size", referenced from:
      my_aes_get_size(unsigned int, my_aes_opmode) in libmysqlcppconn-static.a(my_aes_openssl.cc.o)
  "_EVP_CIPHER_iv_length", referenced from:
      my_aes_encrypt(unsigned char const*, unsigned int, unsigned char*, unsigned char const*, unsigned int, my_aes_opmode, unsigned char const*, bool) in libmysqlcppconn-static.a(my_aes_openssl.cc.o)
      my_aes_decrypt(unsigned char const*, unsigned int, unsigned char*, unsigned char const*, unsigned int, my_aes_opmode, unsigned char const*, bool) in libmysqlcppconn-static.a(my_aes_openssl.cc.o)
      my_aes_needs_iv(my_aes_opmode) in libmysqlcppconn-static.a(my_aes_openssl.cc.o)
  "_FIPS_mode", referenced from:
      set_fips_mode(unsigned int, char*) in libmysqlcppconn-static.a(viosslfactories.cc.o)
      get_fips_mode() in libmysqlcppconn-static.a(viosslfactories.cc.o)
  "_FIPS_mode_set", referenced from:
      set_fips_mode(unsigned int, char*) in libmysqlcppconn-static.a(viosslfactories.cc.o)
  "_SSL_get_peer_certificate", referenced from:
      ssl_verify_server_cert(Vio*, char const*, char const**) in libmysqlcppconn-static.a(client.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

据我所知,这意味着程序无法链接openSSL库中的一些头文件,即使我在CMakeLists.txt中链接openSSL:

cmake_minimum_required(VERSION 3.24)

set(PROJECT_NAME "ChatBot")
set(CMAKE_CXX_STANDARD 17)
set(PROJECT_PATH /myPath)

project(${PROJECT_NAME})

if(EXISTS ${CMAKE_BINARY_DIR}/conanBuild/conanbuildinfo.cmake)
    include(${CMAKE_BINARY_DIR}/conanBuild/conanbuildinfo.cmake)
    conan_basic_setup()
else()
    message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run ./build.sh first")
endif()

include_directories(
    ${PROJECT_PATH}/mysql-connector/include
    ${PROJECT_PATH}/mysql-connector/include/cppconn
)

link_directories(mysql-connector/lib)

add_library(libmysqlcppconn STATIC IMPORTED)
set_property(TARGET libmysqlcppconn PROPERTY IMPORTED_LOCATION ${PROJECT_PATH}/mysql-connector/lib/libmysqlcppconn-static.a)

FILE(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.h)
add_executable(${PROJECT_NAME} ${SOURCE_FILES} main.cpp)

find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME}
        libmysqlcppconn
        OpenSSL::SSL
        OpenSSL::Crypto
        ${CONAN_LIBS}
)

更多信息:

openssl@3: stable 3.1.0 [keg-only] (via homebrew)
   - keg only so I added 
           export PATH="/usr/local/opt/openssl@3/bin:$PATH"
           export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
           export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
     to my .zshrc as homebrew suggested this

cmake: stable 3.26.0
mysql-connector-c++ 1.1.13
Additional packages installed by conan:
    libcurl/7.87.0
    cpr/1.10.0
    boost/1.81.0
    nlohmann_json/3.11.2

OSX Ventura 13.1

我目前在我的witts结束与这个问题,并希望有人知道这里的问题可能是什么。

svujldwt

svujldwt1#

使用连接器8.0。
它有两个不同的API,JDBC是你的程序所期望的。
OpenSSL 3.0有一个不同的API,这就是为什么连接器1.x不起作用。
PS:使用连接器到您的系统,因为它是针对系统openssl链接的。

相关问题