How to setup a C++ project with MySQL Connector and CMake

Hi there,

despite having developed applications in C++ for about two to three years, I never had to setup a project on my own.

Because I knew I wanted to store information in a database,I set off to create a simple CMake project with one executable linked to the MySQL Connector for C++, and instantly failed...

Since I - oddly - could not find helpful information anywhere else, I hope one of you could be my savior.

More information on: https://stackoverflow.com/questions/51956116/how-to-setup-a-c-project-with-mysql-connector-and-make

Because it would not fit in one post.
Does it have to be MySQl ?
Much easier to use is SQLite - just one .h to include and one .cpp to add to the project.
Do you still use libmysqlcppconn-static.a instead of libmysqlcppconn8-static.a? This was noted in the comments, and the documents also expand on this.

There are also alot of other variables too like are you 100% sure that you have the right bit's, are you using the exact same clang compiler that built the sql binaries, and are you sure the paths are correct.

But my best guess is that you are missing the 8.

here are the docs https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-apps-make.html
Last edited on
Sadly that did not fix it. But I made another big mistake. I used connector-cpp 1.1 code which would not work anyway.

To be sure that I do not have any compiler version issues (I checked and they matched), I switched to building the libs myself.

I got that to work, but I can not link to these library either...
I get:
ignoring file ../libs/libmysqlcppconn8.dylib, file was built for unsupported file format ( 0x62 0x6F 0x6F 0x6B 0x00 0x00 0x00 0x00 0x6D 0x61 0x72 0x6B 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): ../libs/libmysqlcppconn8.dylib

which honestly does not mean anything to me ...
can you try using the 32 bit binaries?

edit: I think I got it wrong, more like, you should build the project as 32 bit to see if it works, don't forget to clean all object files.
Last edited on
Why should I use 32 bit. My system uses 64bit and I see no reason that should not work. Maybe there are cmake flags set in the mysql connector which select a certain compiler oder certain libraries. But I do not know how I could find such and if that is even possible.
From my quick google, it seems obvious that this is a bit problem, I don't doubt that you have 64 bits or that 32 bits or better, but it seems like you may have accidentally downloaded the 32 bit binaries.
Topic archived. No new replies allowed.