C++ MySQL++ Tutorial

Submitted on: 1/8/2015 4:26:00 AM
By: Todd M. Knisely (from psc cd)  
Level: Advanced
User Rating: By 3 Users
Compatibility: C++ (general), Microsoft Visual C++
Views: 3811
     At the request of "Karthik A" I am posting an in depth tutorial on the use of VC++ & MySQL++ development. I will take you through it step by step so that you may get your applications up and running as quickly as possible.


Lets begin with what you will need.


  • MySQL database installed to C:\mysql
  • Visual C++ .NET 2003
  • MinGW 5.0 [ ]
  • MySQL ++ Source 2.0.7 tarball []

Optional Components to assist development:

  • PHP & MySQL enabled web server
  • phpMyAdmin to assist database management

Lets begin. I am going to assume that you have mysql installed and running
to C:\mysql and MySQL ++ extraced to C:\mysql++.


MySQL++ only builds under Visual C++ 7.1 (a.k.a. Visual Studio
2003, a.k.a. cl version 13.10) or later. Earlier versions did
not support a sufficiently broad set of the Standard C++ language.

About the New Build System (makemake)
As of MySQL++ v2.0, we have changed the VC++ build system over to
a command-line based system, instead of Visual Studio project
files. We've done this for many reasons:

1. Not everyone has the IDE: Microsoft has made their
command-line tools available for free at various times,
and these offers usually do not include the Visual
Studio IDE.

2. Project files tend to be tied to one version of
Visual Studio. Newer versions can migrate old project
files, but then old versions cannot read the new files.
So, each time there's a new version of Visual Studio,
there's a transition period where at least two versions
of the IDE are still in common use. Makefiles,
by contrast, work with all versions, without changes.

3. Standardization: project files types proliferated
in the old system, and we would frequently forget to
update all of the project files when changing the
corresponding autotools files. In the new system,
there are only two places where build system changes
need to be made: one for systems using the autotools,
and one for systems using makemake.

So, please do not ask for the Visual Studio project files to
return. They cause more problems than they solve.

Prerequisite: GNU make
The Makefiles generated by makemake require GNU make.
They used to work with Microsoft's nmake, but that held us
back from adding several useful features.

We've tested with two ports of GNU make for Windows: Cygwin and

To get GNU make through Cygwin, go to and
get the Cygwin setup program. GNU make isn't part of the
default installation, so you will have to add it. It's in
the Devel category.

To get the MinGW version of GNU make, go to
and download it directly. You shouldn't need to download
anything but the GNU make package, as it should run standalone.

Once you have done either of these, you will need to add
the bin directory containing GNU make to your PATH. If you
don't know how to do this, open Windows Help and search for
Environment Variables.

Building the Library and Example Programs
First, you need to open a Windows command prompt (cmd.exe).
The easiest way to do this is to go into your Visual Studio
program group under the Start menu and in the Tools folder
find the Command Prompt item. All it does is open a command
window and run a batch file called vcvars32.bat to set
up the environment variables needed to run the Visual C++
command-line tools. If you have a different way to open a
command prompt that you prefer, you can use that and run the
vcvars32.bat file by hand.

To create the Makefiles, say "makemake vc" in the mysql++ root
directory. You only have to do this once, unless you change
Makefile.base or

Now you can run GNU make to build the library and examples.
If you've installed GNU make through Cygwin, the command is
"make". If you're using the MinGW version of GNU make, it's
"mingw32-make"[mingw32-make is the command you will use] instead.

The build process creates debug and release versions of the MySQL++
DLL, as well as import libraries for those DLLs. It's possible to
create a static library, but we don't do this in the distributed
Makefiles because linking to such a library is a license violation
for programs not licensed under the GPL or LGPL. Using the
library in DLL form avoids this problem.

The build process also builds the example programs. They are built
in debug mode. You should run the major examples to make sure
the library is built correctly; see examples/README details.

Once the library is built and you're satisfied that it's working
correctly, say "install vc" [only under w32 install is a batch file that will
install your release libs and DLLs to a sub directory of mysql++ ]
at the project root.

If you didn't install MySQL in c:\mysql, you will have to change in the lib and examples sub directories and re-run
"makemake vc". You may also look at changing these files for
various other reasons, such as if you don't like the way we name
the DLL file, or want the 'install' target to put the MySQL++
development files somewhere other than c:\mysql++.

Using MySQL++ in Your Own Projects

Fire up VS .NET, create a Blank Solution. Add a new project.
Choose Empty Project (.NET) under Visual C++ Projects. Add a
.cpp file to the solution so it _knows_ it's a C/C++ solution.
Go to the solution Property Pages and make the following changes.
(Where it doesn't specify Debug or Release, make the change to
both configurations.)

o Under Configuration Properties::General change "Use
Managed Extensions" to "No"

o Under C/C++::General add to "Additional Include
Directories": c:\mysql++\include, c:\mysql\include

o Under C/C++::Code Generation change "Runtime Library" to
"Multi-threaded Debug DLL (/MDd)" for the Debug
configuration. For the Release configuration, make it
"Multi-threaded DLL (/MD)".

o Under Linker::General add to "Additional Library
Directories": "c:\mysql\lib\debug, c:\mysql++\vc\debug"
for the Debug configuration. For the Release configuration,
make it "c:\mysql\lib\opt, c:\mysql++\vc\release"

o Under Linker::Input add to "Additional Dependencies":
"libmysql.lib wsock32.lib mysqlpp.lib"

If You Run into Problems...
Especially if you have linking problems, make sure your project
settings match the above. Visual C++ is very picky about things
like run time library settings. If you still can't get things
going, try running one of the example programs. If it works,
the problem is likely in your project settings, not in MySQL++.

Final Note: To run the application ou will need to copy the
proper DLL from the mysql++ directory to your debug or
release folder within your visual studio project, or you may
add the location to your library path. I suggest simply copying

Providing you installed everything to the location I have specified,
the paths to the important DLLs are as follows:

mysqlpp.dll for debug builds :C:\mysql++\vc\debug
mysqlpp.dll for release builds :C:\mysql++\vc\release

libmysql.dll for debug builds: C:\mysql\lib\debug
libmysql.dll for release builds: C:\mysql\lib\opt

Please send any questions to me anytime at

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.