Port MySQL C/C++ connector to Mingw64
Libraries included: MySQL C++ Connector 1.1.5 MySQL C Connector 6.1.5
The goal of this project was/is to provide functional support of the build/use of the MySQL C/C++ connector with the Mingw64 toolset.
Out of the box, the MySQL connectors only support visual studio and namely, Microsoft proprietary functionality.
Pre-built 32/64 bit libraries are included in this repo
Here are some notable source changes:
-
localtime_r/s not supported by Mingw64 (as of now). Changed to regular localtime (Should be thread safe, not re-entrant safe though)
-
__try __catch is not standard C. Implemented this functionality for Mingw64 with libseh: http://www.programmingunlimited.net/siteexec/content.cgi?page=libseh
-
Removed any references to strtok_r/s. MySQL has a custom implementation within their source which will have to do
-
Fixed syntax errors. Mainly syntax issues which prevent compiling with GCC ( will squeak by with MS compiler :p )
-
Re-implemented timespec() - skip Mingw64 declaration with #define
-
Fixed i64, LL, ULL references...
Building:
You can use the pre-built binaries with your project. Remember to link with: ws2_32, secur32, mysqlclient
To build Cppconn with CMake:
- Include something like this in C/CXX flags: -Ic:/boost -LPATH_TO_LIBMYSQL -DSECURITY_WIN32
- Link with these libs: -lmysqlclient -lws2_32 -lsecur32
Make sure you have a Mingw64 toolchain installed (I use WinBuilds) and the bin/ in your PATH variable. When generating with CMake, choose the source dir of each project respectively, and use "Mingw Makefiles". The connector c++ library also depend on Boost, so make sure you have Mingw64 compiled Boost somewhere on your box and set the 'Boost_INCLUDE_DIR' CMAKE var to eg: 'C:/boost'
If you get errors while generating, change '_found_header' to the MySQL C connector include dir...eg: 'C:/Program Files/MySQL/MySQL Connector C 6.1/include' (or the source contained in this repo). Otherwise, you will need to modify the cmakelists file and add this dir using include_directories()
1 ) Add to linked libs: -lmysqlclient -lwsock32 -lws2_32 -lsecur32
-
Add search path for mysqlclient lib, eg: -L{PATH_TO}MYSQLCLIENT.A
-
Set CMake var '_found_header' to path to MySQL C Connector /include
-
CMake var 'MYSQL_LIB' to path to 'libmysqlclient.a'
-
Configure/generate and build with mingw32-make or (make)
- Include search path to libseh header/lib in c/xx flags: -IPATH_TO_LIBSEH\libseh -LPATH_TO_LIBSEH\libseh
- libseh is included in the c connector source dir
- Link with : -lseh -lmingwex
note I could not link the 32 bit DLLs. There is quite a bit of name mangling when trying to link and I decided to just support static libs
-
Include search path for libseh header/libs, eg: -I{PATH_TO_LIBSEH} -L{PATH_TO_LIBSEH}
-
Link C compiler with -lseh32
-
Add -lws2_32 -lsecur32 to CXX flags
-
Set CMake var 'DISABLED_SHARED' to true
-
Generate/configure and build with mingw32-make or make