Friday, March 18, 2016

Compiling sysbench.exe in Windows

Since there is relatively no information other than the README-WIN file which is shipped along with the sysbench source code as to how to compile sysbench, I thought I would detail the steps I had done as I had to go through many hurdles to get this to compile.

Download the latest source files for sysbench from github

https://github.com/akopytov/sysbench

I was using sysbench-0.4.12.10 for my compilation.

Now this is how the README-WIN looks like.. Fairly simple right?? I also assumed so..

How to build on Windows

You need CMake (download from http://www.cmake.org/) and Visual Studio 2005 or 
later (free Express edition should work ok)

1.Open Visual Studio command line prompt
2.To build with MySQL support, you will need mysql.h header file and client 
library libmysqld.lib
One can get them e.g by downloading and unpacking the "zip" distribution of mysql

- Append directory where libmysql.lib is located to environment variable LIB, e.g
  set LIB=%LIB%;G:\mysql-noinstall-6.0.6-alpha-win32\mysql-6.0.6-alpha-win32\lib\opt

- Append directory where mysql.h is located to environment variable INCLUDE, e.g
  set INCLUDE=%INCLUDE%;G:\mysql-noinstall-6.0.6-alpha-win32\mysql-6.0.6-alpha-win32\include
3.In the sysbench directory, execute cmake -G "Visual Studio 9 2008" 
4.Open sysbench.sln in Explorer and build Relwithdebinfo target.
  Alternatively, from the command line, issue  
  vcbuild /useenv sysbench.sln "Relwithdebinfo|Win32"


I already had Microsoft Visual Studio 2010 Express Edition installed on my Windows 7 machine. So I proceeded to download CMake utility from https://cmake.org/.

I installed CMake. Now my intention was to run a MySQL benchmark. So I had to compile it with the MySQL header files and libraries. So I downloaded the MySQL edition "mysql-installer-community-5.7.11.0".

Now this is the step which took me a while to figure out. When you install MySQL on a 64 bit machine, install the x86 binaries for MySQL by going to the Advanced option during installation. Do not install the 64 bit binaries. This will cause linking issues later on when compiling sysbench.

Now you can follow the steps for installation as per the README-WIN. The Visual Studio command prompt can be found under Programs->Visual Studio 2010 Express ( in my case ).

The INCLUDE directory which I had set was C:\Program Files (x86)\MySQL\MySQL Server 5.7\include

This should container the mysql.h file.

The LIB directory which I had set was C:\Program Files (x86)\MySQL\MySQL Server 5.7\lib. 

This should contain the libmysql.dll and libmysql.lib files.

Another snag which I hit in compilation issue during cmake "fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt"

Basically if you have .Net Framework 4 installation in the same machine, it would render the cvtres.exe file in the 2010 folder corrupt. So I did a search for the cvtres.exe in my machine. Copied the cvtres.exe from the .Netframework folder to the VC2010 bin location or you can also rename the cvtres.exe in "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" to cvtres-old.exe

Navigate to the sysbench directory in the Visual Studio Command prompt and execute 

cmake -G "Visual Studio 10 2010"

It should make fine.

Open the sysbench.sln file and build with the Relwithdebinfo|Win32 in the Debug options.


Add the following paths in the include directories and the lib directories in Project properties, VC++ directories.

C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\include;C:\Program Files (x86)\MySQL\MySQL Server 5.7\include;

C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\lib;C:\Program Files (x86)\MySQL\MySQL Server 5.7\lib

You are ready to build and should possibly not face any issues.