You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake配置MySQL Connector/C++时链接库失败求助

Fixing "cannot find -lmysqlcppcon" when linking MySQL Connector/C++

Here are actionable fixes for your linker error:

  1. Verify the library filename in your lib directory
    Navigate to C:/MySQL/MySQL Connector C++ 8.4/lib64 and check the actual library files present. The linker expects a file matching mysqlcppcon, 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 the target_link_libraries line to use the base name of the file (omit lib prefix and .a/.lib suffix). For example, if the file is libmysqlcppcon8.a, use mysqlcppcon8 instead of mysqlcppcon.
  2. 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.

  3. 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).

  4. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 03:52:02