Dejan Levec

C++ libraries on Windows are nightmare

How would you get C# library to work? Simple, copy .dll to VS solution.
How would you get C++ library to work on Linux? apt-get install libmysql-c++ (or equivalent for distro of your choice)
How would you get C++ library to work on Linux if previous statement fails? ./configure && make && make install

How would you get C++ library to work on Windows with Visual Studio? Wau, right now I’m not sure if that is even possible.

So why would I even try do something so impossible? Lately I have been wanting to dive into game programming and after going through some Ogre3D tutorials this morning, I want to learn how MMORPG are made (without first M, for now :-)). And how can you make MMORPG server without some way to save data? Short answer? You can’t.

My first thought was to use some kind of NoSQL database like MongoDB which I previously used on some Python/PHP projects. First thing I did was to Google “MongoDB C++” and I happily found out, that there is a full featured C++ connector. Sadly, there is a catch. Because libraries don’t mix well between compilers, there is no prebuild library I can simply use with Visual Studio.
I guess the only way is to manually compile it from the source code. Of course, this doesn’t seem so simple as it would be on Windows and after an hour I gave up thinking, that there must be a database with prebuild library.

My next thought was Drizzle, especially because I heard it has asynchronous C++ bindings. Sadly, there is no precompiled and ready to use server for Windows, much less would there be any such bindings.

MySQL C++ Connector
And I’m back where I started, to my dear old friend MySQL. No big suprise here, I actually found precompiled library that should work with VS. However, that doesn’t mean it would work. After some Googling I got it to the point where my program compiles, but it fails to connection with some unknown problem (and I mean it, error message was “Unknown exception”).

Yay I thought, don’t have much choice but to compile it from the source. This was more like a breeze compared to MongoDB, although I spend a few minutes on one particular error:

I entirely gave up on trying to set custom MySQL directory for CMake. No matter what I changed, cmake failed to find MySQL include directory. Mind you, that was necessary only because I have x64 version of MySQL installed and need 32-bit library because I don’t want to deal with another series of problems. Although I have a feeling that cmake wouldn’t be able to find MySQL installed in C:\Program Files considering that environmental variable ProgramFiles points to C:\Program Files (x86).

The last resort was to copy 32-bit MySQL files to folder where they would reside should I installed MySQL Server with 32-bit installer.

Steps to compile C++ Connector with VS2010:
– download MySQL C++ Connector source code to anywhere you want
– download MySQL 32-bit Server if you don’t have it already and copy files to C:\Program Files (x86)\MySQL\MySQL Server 5.5
– download and install CMake
– move to directory where you unzipped connector and execute: cmake -G “Visual Studio 10”
– open ALL_BUILD project with VS2010
– compile everything

Or you can just download precompiled connector: mysql-connector-c++ (32-bit MySQL C++ connector 1.1.0 for MySQL Server 5.5)
Archive contains static and dynamic connector, compiled as both, Debug and Release version.

Leave a Reply

Your email address will not be published. Required fields are marked *