找不到符号 mysql_select_db@libmysqlclient_16 的版本节点

version node not found for symbol mysql_select_db@libmysqlclient_16

我试图在 linux 上使用 mysql c api 构建我的应用程序,但在 link 阶段出现此错误,它在 [=29] 上运行良好=].请帮忙,谢谢!

错误信息:

/bin/ld: myapp.so : version node not found for symbol mysql_select_db@libmysqlclient_16
/bin/ld: failed to set dynamic section sizes: Bad value

OS: CentOS 7, 64-bit, (VM on virtual box)

Mysql: 5.6.24 (社区版, 通过 yum 安装)

.bashrc 文件

export LIBMYSQL_INCLUDE_DIR=/usr/include/mysql
export LIBMYSQL_LIBRARY=/usr/lib64/mysql
export LD_LIBRARY_PATH=/usr/lib64/mysql:$LD_LIBRARY_PATH

cmake文件:(变量根据环境变量设置)

FILE(GLOB SRC_MYAPP myapp/*.c myapp/*.h)
INCLUDE_DIRECTORIES(${LIBMYSQL_INCLUDE_DIR})

ADD_LIBRARY(myapp ${SRC_MYAPP})
IF (MSVC_IDE)
  TARGET_LINK_LIBRARIES(myapp ${LIBMYSQL_LIBRARY}/libmysql)
ELSE ()
  TARGET_LINK_LIBRARIES(myapp ${LIBMYSQL_LIBRARY}/libmysqlclient_r.a)
ENDIF ()

将@hank 的评论作为答案

我想你应该在 add_library 之前添加 link_directories(/usr/lib64/mysql),然后添加 target_link_libraries(myapp mysqlclient_r) – hank May 12 at 12:50