MySQL Forums
Forum List  »  Source, Builds, Binaries

Re: MySQL source build on WINDOWS using Mingw
Posted by: Creative Team
Date: July 14, 2011 11:15PM

On Windows platform, compilation on MySQL C++ connector source code is officialy supported only using visual studio. But, I was able to compile connector code and run examples using MinGW compiler. These are complete steps from starting from dowloading, compiling and building examples using MySQL C++ connector on windows using mingw c++ compiler.

Read the MySQL C++ documentation for your knowledge.
http://forge.mysql.com/wiki/Connector_C++

To build the connector and examples you will need to download following tools.

1. MySQL Server 5.1 or above
2. MinGW 3.4.5
3. make
4. CMake

1. Download and install MySQL Server
Make sure that /bin directory is in system path.

2. Download and install MinGW C++ compiler. If you download a zip archive then just unpack the MinGW files in folder of your choice. Make sure that /bin directory is in system path.
http://sourceforge.net/projects/mingw/

3. Download and install/unpack CMake
http://www.cmake.org/cmake/resources/software.html
Make sure that /bin directory is in system path.

4. Download and install make
http://gnuwin32.sourceforge.net/packages/make.htm
Make sure that /bin directory is in system path.

Downloading the connector source code
Connector download url:
http://downloads.mysql.com/forge/connector_cpp_preview

A new version on connector source code is availabe at:
http://dev.mysql.com/get/Downloads/Connector-C%2B%2B/mysql-connector-c%2B%2B-1.0.5.tar.gz/from/http://mysql.mirror.redwire.net/

But I compiled using version 1.0.0

1. Extract the tar.gz file say
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview

2. Open a command prompt and type following command
cd C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview

3. Type cmake -G "MinGW Makefiles" to generate make files for building the connector. The command output should be like.

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: C:/Qt/2009.03/mingw/bin/gcc.exe
-- Check for working C compiler: C:/Qt/2009.03/mingw/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/2009.03/mingw/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/2009.03/mingw/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- ENV{MYSQL_DIR} =
-- MYSQL_INCLUDE_DIR = C:/Program Files/MySQL/MySQL Server 5.1/include
-- MySQL Include dir: C:/Program Files/MySQL/MySQL Server 5.1/include
-- MySQL Library dir: C:/Program Files/MySQL/MySQL Server 5.1/lib/opt
-- MySQL CFLAGS:
-- MySQL Link flags:
-- Configuring cppconn
-- Looking for include files HAVE_GLIB_H
-- Looking for include files HAVE_GLIB_H - not found.
-- Configuring drivermanager
-- Configuring test cases
-- Configuring examples
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Program Files/MySQL/cpp_connector/mysql_connector_cpp_1_0_0_preview

4. Type make to build the connector.

You will get plenty of errors like:
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:592: error: `UINT16' does not name a type
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:593: error: `UINT16' does not name a type
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:594: error: `UINT16' does not name a type
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:727: error: too many initializers for `sql::mysq
l::MY_UNICASE_INFO'
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:727: error: too many initializers for `sql::mysq
l::MY_UNICASE_INFO'
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:727: error: too many initializers for `sql::mysq
l::MY_UNICASE_INFO'
C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\cppconn\mysql_ps_resultset.cpp:727: error: too many initializers for `sql::mysq
l::MY_UNICASE_INFO'

Don't get scared. These errors will go away in no time.
Open mysql_ps_resultset.cpp and go to line number 564 and comment the following line and save.
#define uint16_t UINT16

again type make to build the connector.

and this time output should be like

C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview>make
[ 39%] Built target mysqlcppconn
[ 78%] Built target mysqlcppconn-static
[ 82%] Built target static_test
[ 85%] Built target connect
[ 89%] Built target prepared_statement
[ 92%] Built target resultset
[ 96%] Built target resultset_meta
[100%] Built target statement

And you are done.

Now place the libmysqlcppconn.dll (This file is created after compilation is complete) file in system path.

Running the examples

1. Start MySQL Server.

2. Open command prompt and go to examples directory.

cd C:\Program Files\MySQL\cpp_connector\mysql_connector_cpp_1_0_0_preview\examples

3. Type conenct.exe and you should see output like this:

Connector/C++ connect basic usage example..
Test table created
Test table populated
Running 'SELECT id, label FROM test ORDER BY id ASC'
Number of rows res->rowsCount() = 4
Fetching row 0 id = 1, label = ''
Fetching row 1 id = 2, label = 'a'
Fetching row 2 id = 3, label = 'b'
Fetching row 3 id = 4, label = 'c'
Fetching 'SELECT id FROM test ORDER BY id DESC' using type conversion
Fetching row 0 id (int) = 4 id (boolean) = true id (long) = 4
Fetching row 1 id (int) = 3 id (boolean) = true id (long) = 3
Fetching row 2 id (int) = 2 id (boolean) = true id (long) = 2
Fetching row 3 id (int) = 1 id (boolean) = true id (long) = 1
UPDATE indicates 1 affected rows
Expecting id = 100, label = 'y' and got id = 100, label = 'y'
done!

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: MySQL source build on WINDOWS using Mingw
21028
July 14, 2011 11:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.