Basically I'm trying to connect mysql library in my "CMakeList.txt" file.
When i compile the "main.cpp" file the compiler gives this error:
C:/Users/Acer/Desktop/Uni/CP2/872539db-gr13-repo/Project/cmake-build-debug/Project.exe:
error while loading shared libraries: libmysql.dll: cannot open shared
object file: No such file or directory
Process finished with exit code 127
The point is the file "libmysql.dll" exist.
This is my "CMakeList.txt" file:
cmake_minimum_required(VERSION 3.21)
project(Project)
set(CMAKE_CXX_STANDARD 20)
set(FULL_PATH_TO_MYSQL_DIR ../Project/libraries/mysql/mysql-8.0.28-winx64)
include_directories(${FULL_PATH_TO_MYSQL_DIR}/include)
link_directories(${FULL_PATH_TO_MYSQL_DIR}/lib)
link_libraries(libmysql)
add_executable(Project
main.cpp)
target_link_libraries(Project libmysql)
This is my "main.cpp" file:
#include <iostream>
#include <mysql.h>
MYSQL *connection;
class Dd_response
{
public:
static void connectionFunction()
{
connection= mysql_init(nullptr);
if(connection)
std::cout<<"Database connected!!"<<std::endl;
else
std::cout<<"Failed to connect!!"<<mysql_errno(connection)<<std::endl;
connection= mysql_real_connect(connection, "127.0.0.1", "root", "", "online_shop", 3306, nullptr, 0);
if(connection)
std::cout<<"Database connected to mysql!!"<<connection<<std::endl;
else
std::cout<<"Failed to connect!!"<<mysql_errno(connection)<<std::endl;
}
};
int main()
{
std::cout<<"Hello world";
Dd_response::connectionFunction();
return 0;
}
This is my "Project" folder: