我正在尝试使用libmysqlcppconn
用新的cmake
版本8构建简单的示例,我下载了连接器并从源代码构建和安装。但是当我尝试使用cmake
或Clion
run构建我的世界时出现错误
/usr/bin/ld: CMakeFiles/hellogcp.dir/src/main.cpp.o: en la función `mysqlx::abi2::r0::internal::Result_common<mysqlx::abi2::r0::internal::Result_detail>::~Result_common()':
/usr/include/mysqlx/devapi/result.h:71: referencia a `mysqlx::abi2::r0::internal::Result_detail::~Result_detail()' sin definir
/usr/bin/ld: CMakeFiles/hellogcp.dir/src/main.cpp.o: en la función `mysqlx::abi2::r0::internal::Result_common<mysqlx::abi2::r0::internal::Result_detail>::~Result_common()':
/usr/include/mysqlx/devapi/result.h:71: referencia a `mysqlx::abi2::r0::internal::Result_detail::~Result_detail()' sin definir
/usr/bin/ld: CMakeFiles/hellogcp.dir/src/main.cpp.o: en la función `mysqlx::abi2::r0::Result::~Result()':
/usr/include/mysqlx/devapi/result.h:71: referencia a `mysqlx::abi2::r0::internal::Result_detail::~Result_detail()' sin definir
/usr/bin/ld: CMakeFiles/hellogcp.dir/src/main.cpp.o: en la función `mysqlx::abi2::r0::Result::~Result()':
/usr/include/mysqlx/devapi/result.h:71: referencia a `mysqlx::abi2::r0::internal::Result_detail::~Result_detail()' sin definir
我通过
进行测试find_library(MYSQL_LIB mysqlcppconn8)
target_link_libraries(${PROJECT_NAME} ${MYSQL_LIB})
但是无论是否有find_library
,错误都是相同的。
如果我使用:
set(EXTRA_LIBRARY "mysqlcppconn8")
我知道
/usr/bin/ld: can not be found -lmysqlcppconn8
/usr/bin/ld: can not be found -lmysqlcppconn8
具有:
g ++ -std = c ++ 11 -I ... / include -L ... / lib64 src / main.cpp -lmysqlcppconn8 -o app
完美构建。但是,如果删除-lmysqlcppconn8
,则会得到与cmake
相同的错误。
如何将-lmysqlcppconn8
添加到cmake
?
答案 0 :(得分:0)
通过添加具有扩展名的库来修复
if (BUILD_MODE STREQUAL "Docker")
message("***************************** USING STATIC LIBS **************************************")
add_compile_definitions(STATIC_CONCPP)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-static")
set(DCMAKE_FIND_LIBRARY_SUFFIXES .a)
find_library(PISTACHE_LIB libpistache.a)
find_library(MYSQL_LIB libmysqlcppconn8-static.a)
set(MY_LIBS ${PISTACHE_LIB} ${MYSQL_LIB})
else()
message("***************************** USING SHARED LIBS **************************************")
find_library(PISTACHE_LIB libpistache.so)
find_library(MYSQL_LIB libmysqlcppconn8.so)
set(MY_LIBS ${PISTACHE_LIB} ${MYSQL_LIB})
endif (BUILD_MODE STREQUAL "Docker")
unset(BUILD_MODE CACHE)