I have been trying to develop a simple c++ program to connect to mysql using the mysql connector/c++ library. I have been running into issues after issues. This is the next hurdle. I am new to CMake & Make, but have been trying to use it to build this project. I've downloaded all the recent packages, dependencies, softwares, etc.: MySQL 9.3, MySQL Connector/C++ 9.3, OpenSSL@3. I am working on my Mac terminal.
My program: /Users/{user}/Documents/Projects/SQL/src/main.cpp
#include <iostream>
#include "/usr/local/mysql-connector-c++-9.3.0/include/mysql/jdbc.h"
using std::cout;
int main(){
sql::mysql::MySQL_Driver *driver;
driver = sql::mysql::get_mysql_driver_instance();
cout<<"Hello"<<"\n";
return 0;
}
CMake file (CMakeLists.txt): /Users/{user}/Documents/Projects/SQL/
cmake_minimum_required(VERSION 4.0.1)
project(mysql_tut)
#set some path variables
set(MYSQL_PATH "/usr/local/mysql-connector-c++-9.3.0/")
set(MYSQL_LIB_PATH "${MYSQL_PATH}lib64/")
#create a variable to hold all necessary library files
file(GLOB LIB_FILES
"${MYSQL_LIB_PATH}libmysqlcppconn.10.9.3.0.dylib"
"${MYSQL_LIB_PATH}libcrypto.3.dylib"
"${MYSQL_LIB_PATH}libssl.3.dylib"
)
#set std=c++11 standard needs to run during compilation
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#set path for builder to look for cmake configure file "mysql-conncpp-config.cmake"
set(CMAKE_PREFIX_PATH "${MYSQL_PATH}")
#find library's cmake config file "mysql-conncpp-config.cmake"
find_package(mysql-conncpp REQUIRED)
#set target and source file
add_executable(main src/main.cpp)
#set target library files
target_link_libraries(main PRIVATE "${LIB_FILES}")
#set target include directory
target_include_directories(main PRIVATE "${MYSQL_PATH}include/mysql")
The MySQL connector library was installed via .dmg in the directory /usr/local/, containing the respective subdirectories for the include files, library files, cmake configuration files, etc.
I created a build directory (same level as the src) /Users/{user}/Documents/Projects/SQL/build/, and changed into it. There, I ran cmake .. command for the Cmake file to generate the make file in the build directory. Following, I ran the make command and the project was built successfully. However, when I try to execute the binary file ./main I receive this error:
dylb[44606] Library not loaded: libcrypto.3.dylib
Reference from: <57D4XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX> /Users/{user}/Documents/Projects/SQL/build/main
Reason: tried: 'libcryto.3.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcrypto.3.dylib'(no such file),
'libcrypto.3.dylib' (no such file), '/Users/{user}/Documents/Projects/SQL/build/libcrypto.3.dylib'
(no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/{user}/Documents/Projects/SQL/build/libcrypto.3.dylib'
(no such file), /Users/{user}/Documents/Projects/SQL/build/libcrypto.3.dylib' (no such file)
zsh: abort ./main
In certain cases, I get an error that says no such files for libssl.3.dylib. I am not sure what is going on, because I added in the cmake file, the library files to the target_link_libraries command. I have checked my OpenSSL and I have the latest installed via homebrew at /opt/homebrew/Cellar/. What can be causing this issue?