CMake无法找到mysqlclient库 [英] CMake unable to find mysqlclient library
问题描述
我正在使用 CMake
生成一个makefile,以编译使用boost,eigen和mysqlclient库的C ++项目.
I'm using CMake
to generate a makefile to compile a C++ project that uses the boost, eigen, and mysqlclient libraries.
在生成过程中,代码似乎可以编译,但是在链接阶段我得到了错误
During the make process the code seems to compile, but then at the linking stage I get the error
ld: library not found for -lmysqlclient
我有一行 target_link_libraries(my_executable mysqlclient)
在我的 CMakeLists.txt
文件中.当我删除该行时,我不再得到该错误消息,但是却得到了一长串未定义的符号错误(都与mysql有关).该项目可以在Xcode中正确构建,因此我知道至少在我的计算机上设置了mysql客户端库.有提示,建议吗?
I have the line target_link_libraries(my_executable mysqlclient)
in my CMakeLists.txt
file. When I remove that line, then I no longer get that error message, but then I get a long list of undefined symbols errors (all having to do with mysql).
The project builds correctly in Xcode, so I know that at least the mysql client libraries are set up on my machine.
Any tips, suggestions?
推荐答案
您将要使用Kitware中的 FindMySQL.make
包(将文件保存在此处:
You will want to use the FindMySQL.make
package from Kitware (save the file here: https://cmake.org/Wiki/CMakeUserFindMySQL as ${CMAKE_SOURCE_DIR}/cmake/FindMySQL.cmake
), then find the library:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(MySQL)
最后,您在cmake中的链接步骤应替换为
Finally, your link step in cmake should be replaced with
target_link_library(myexecutable ${MYSQL_LIBRARY})
$ {MYSQL_LIBRARY}
应该包含要链接的库文件的标准路径.
${MYSQL_LIBRARY}
should contain the fully qualified path to the library file that you want to link with
这篇关于CMake无法找到mysqlclient库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!