CMake配置MySQL Connector/C++时链接库失败求助
Here are actionable fixes for your linker error:
Verify the library filename in your lib directory
Navigate toC:/MySQL/MySQL Connector C++ 8.4/lib64and check the actual library files present. The linker expects a file matchingmysqlcppcon, but common variations in MySQL Connector/C++ include:mysqlcppcon8.lib(versioned MSVC library)libmysqlcppcon8.a(versioned MinGW static library)mysqlcppcond.lib(debug MSVC library)
Update thetarget_link_librariesline to use the base name of the file (omitlibprefix and.a/.libsuffix). For example, if the file islibmysqlcppcon8.a, usemysqlcppcon8instead ofmysqlcppcon.
Use the MinGW-compatible connector build
MySQL Connector/C++ provides separate binaries for MSVC and MinGW. If you installed the MSVC version, MinGW's linker won't recognize its libraries. Download the MinGW-specific package from MySQL's official site, replace your current installation, and confirm the path in your CMakeLists.txt is correct.Match project architecture to the connector
If your CLion project is set to build 32-bit binaries but you're using the 64-bit connector library (or vice versa), the linker will fail. Check your project settings in CLion to ensure the build architecture matches the connector's (both 32-bit or both 64-bit).Simplify your CMake configuration (optional but recommended)
Instead of manually adding every include directory, use the connector's CMake config file for more reliable setup:set(CMAKE_PREFIX_PATH "C:/MySQL/MySQL Connector C++ 8.4") find_package(MySQLConnectorCPP REQUIRED) target_link_libraries(2024__TAB_DSA__8_BRODZIAK PRIVATE cpr::cpr MySQLConnectorCPP::mysqlcppconn ) target_include_directories(2024__TAB_DSA__8_BRODZIAK PRIVATE ${MySQLConnectorCPP_INCLUDE_DIRS})This automatically pulls in the correct include paths and libraries without manual path management.
Content of the question comes from Stack Exchange, question author Michał Brodziak

