I installed MySql connector and i want to use it in my c++ app to connect to database, although i cannot link the library. I tried the way from other stack question so i did:
set(FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR "C:/MySQL/MySQL Connector C++ 8.4")
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/jdbc)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/jdbc/cppconn)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/mysqlx)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/mysqlx/common)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/mysqlx/devapi)
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/mysql)
link_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64)
target_link_libraries(2024__TAB_DSA__8_BRODZIAK
PRIVATE cpr::cpr
mysqlcppcon
)
target_compile_features(2024__TAB_DSA__8_BRODZIAK PRIVATE cxx_range_for)
in mine CMakeLists.txt but it produces error
C:Program FilesJetBrainsCLion 2023.3.4binmingwbin/ld.exe: cannot find -lmysqlcppcon: No such file or directory
I have path defined to my installed Connector and the includes of header files but i still cannot use the files itself and I am not sure why.
It seems like the linker cannot find the MySQL Connector/C++ library file named mysqlcppcon
. This could be due to several reasons:
- The library name might be incorrect in the
target_link_libraries
command. - The path specified in
link_directories
may not contain the actual library files or is incorrect. - If you are using a different version of the connector or if your system is 32-bit, the library might be under a different folder instead of
lib64
.
Here’s what you can do to resolve the issue:
-
Verify that the library name is correct. Often, the library file is named
mysqlcppconn
. If this is the case, update yourtarget_link_libraries
command to use the correct name. -
Check if the library files (
.lib
for static linking or.dll
and.dll.a
for dynamic linking on Windows) are actually present in${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64
. -
If your system is 32-bit or uses a different directory structure, ensure that you’re looking in the right directory for your libraries.
-
You might need to specify the exact name of the library file without the extension in your
target_link_libraries
, e.g., if there’s a file namedlibmysqlcppconn.lib
, just mentionmysqlcppconn
.
Here’s an example of how you might adjust your CMake configuration:
set(FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR "C:/MySQL/MySQL Connector C++ 8.4")
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include)
link_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64)
target_link_libraries(2024__TAB_DSA__8_BRODZIAK
PRIVATE cpr::cpr
mysqlcppconn # Assuming 'mysqlcppconn' is the correct name of your library
)
target_compile_features(2024__TAB_DSA__8_BRODZIAK PRIVATE cxx_range_for)
If none of these steps solve your problem, consider double-checking that you have installed MySQL Connector/C++ correctly and that all necessary environment variables are set up properly. Additionally, make sure that you’re using compatible versions of MySQL Connector/C++ with your compiler and build tools.