【问题标题】:Mysqlcppconn8 and cmake error at build in linux在 Linux 中构建时出现 Mysqlcppconn8 和 cmake 错误
【发布时间】:2019-10-15 11:35:16
【问题描述】:

我正在尝试使用cmake 构建新的libmysqlcppconn 版本8 的简单示例,我下载了连接器并从源代码构建和安装。但是当我尝试使用 cmakeClion 运行构建我的 helloworld 时出现错误

/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

【问题讨论】:

  • 你得到的错误是因为没有链接到所需的库。您的意思是错误是由find_library 方法引起的吗?否则,在描述这种方法时,您所说的“但不起作用”是什么意思?
  • 无论有没有find_library,错误都是一样的

标签: c++ mysql linux cmake


【解决方案1】:

通过添加带有扩展名的库来修复

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)

【讨论】:

    猜你喜欢
    • 2013-05-25
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 2017-04-08
    • 2018-07-24
    • 1970-01-01
    • 2019-02-17
    相关资源
    最近更新 更多