1

我正在尝试将 mysql 连接器导入我的 c++ 项目,但在链接阶段出现错误。这是我的 CMakeLists.txt:

  add_executable(app
    src/main.cpp
  )


  add_library(mysql STATIC IMPORTED)
  set_property(TARGET mysql PROPERTY
    IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/mysql-connector/lib64/libmysqlcppconn8-static.a)

  target_include_directories(
    app
    PRIVATE ${CMAKE_SOURCE_DIR}/src/mysql-connector/include
  )
  target_link_libraries(
    app
    PRIVATE mysql
    PRIVATE crypto
    PRIVATE ssl
    PRIVATE rt
    PRIVATE resolv
  )

这是编译阶段的输出:

/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `main':
/home/chris/app/src/main.cpp:122: undefined reference to `mysqlx::abi2::r0::DbDoc::Iterator::operator*[abi:cxx11]()'
/usr/bin/ld: /home/chris/app/src/main.cpp:124: undefined reference to `mysqlx::abi2::r0::DbDoc::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: /home/chris/app/src/main.cpp:130: undefined reference to `mysqlx::abi2::r0::DbDoc::hasField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: /home/chris/app/src/main.cpp:134: undefined reference to `mysqlx::abi2::r0::DbDoc::Iterator::operator*[abi:cxx11]()'
/usr/bin/ld: /home/chris/app/src/main.cpp:136: undefined reference to `mysqlx::abi2::r0::DbDoc::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'

/usr/bin/ld: /home/chris/app/src/main.cpp:144: undefined reference to `mysqlx::abi2::r0::DbDoc::hasField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::string::traits<char>::from_str(mysqlx::abi2::r0::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/common.h:220: undefined reference to `mysqlx::abi2::r0::string::Impl::from_utf8(mysqlx::abi2::r0::string&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::string::traits<char>::to_str[abi:cxx11](mysqlx::abi2::r0::string const&)':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/common.h:225: undefined reference to `mysqlx::abi2::r0::string::Impl::to_utf8[abi:cxx11](mysqlx::abi2::r0::string const&)'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::string mysqlx::abi2::r0::Value::get<mysqlx::abi2::r0::string>() const':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/document.h:955: undefined reference to `mysqlx::abi2::r0::common::Value::get_ustring[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::Value::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/document.h:1013: undefined reference to `mysqlx::abi2::r0::DbDoc::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::Result::getGeneratedIds[abi:cxx11]() const':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/result.h:211: undefined reference to `mysqlx::abi2::r0::internal::Result_detail::get_generated_ids[abi:cxx11]() const'
/usr/bin/ld: CMakeFiles/app.dir/src/main.cpp.o: in function `mysqlx::abi2::r0::SessionSettings::SessionSettings(mysqlx::abi2::r0::string const&)':
/home/chris/app/src/mysql-connector/include/mysqlx/devapi/settings.h:526: undefined reference to `mysqlx::abi2::r0::common::Settings_impl::set_from_uri(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/app.dir/build.make:236: app] Error 1
make[1]: *** [CMakeFiles/Makefile2:449: CMakeFiles/app.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

导入时#include <mysqlx/xdevapi.h>。任何帮助将非常感激。

4

0 回答 0