This section describes how to build Connector/C++ applications for Linux using the NetBeans IDE.
To avoid potential crashes, the build configuration of Connector/C++ should match the build configuration of the application using it. For example, do not use the release build of Connector/C++ with a debug build of the client application.
Create a new project. Select , . Choose a C/C++ Application and click .
Give the project a name and click . A new project is created.
In the Projects tab, right-click Source Files and select , then .
Change the filename, or simply select the defaults and click to add the new file to the project.
Now add some working code to your main source file. Explore your
Connector/C++ installation and navigate to the
examples directory.
Select a suitable example, such as
standalone_example_docs1.cpp. Copy all the
code in this file, and use it to replace the code in your
existing main source file. Amend the code to reflect the
connection properties required for your test database. You now
have a working example that will access a MySQL database using
Connector/C++.
At this point, NetBeans shows some errors in the source code. Direct NetBeans to the necessary header files to include. Select , from the main menu.
In the Categories: tree view panel, navigate to Build, C++ Compiler.
In the General panel, select Include Directories.
Click the button.
Click , then navigate to the directory
where the Connector/C++ header files are located. This is
/usr/local/include unless you have
installed the files to a different location. Click
. Click .
Click again to close the Project Properties dialog.
At this point, you have created a NetBeans project containing a single C++ source file. You have also ensured that the necessary include files are accessible. Before continuing, decide whether your project is to use the Connector/C++ static or dynamic library. The project settings are slightly different in each case, because you link against a different library.
Using the Static Library
To use the static Connector/C++ library, link against two library files,
libmysqlcppconn-static.a and
libmysqlclient.a. The locations of the files
depend on your setup, but typically the former are in
/usr/local/lib and the latter in
/usr/lib. The file
libmysqlclient.a is not part of Connector/C++, but is
the MySQL client library file distributed with MySQL Server.
(Remember, the MySQL client library is an optional component as part
of the MySQL Server installation process.) The MySQL client library
is also available as part of the Connector/C distribution.
Set the project to link the necessary library files. Select , from the main menu.
In the Categories: tree view, navigate to Linker.
In the General panel, select Additional Library Directories. Click the button.
Select and add the /usr/lib and
/usr/local/lib directories.
In the same panel, add the two library files required for static linking as discussed earlier. The properties panel should then look similar to the following screenshot.
Click to close the Project Properties dialog.
Using the Dynamic Library
To use the Connector/C++ dynamic library, link your project with a single
library file, libmysqlcppconn.so. The location
of this file depends on how you configured your installation of
Connector/C++, but typically is /usr/local/lib.
Set the project to link the necessary library file. Select , from the main menu.
In the Categories: tree view, navigate to Linker.
In the General panel, select Additional Library Directories. Click the button.
Select and add the /usr/local/lib
directories.
In the same panel, add the library file required for static linking as discussed earlier. The properties panel should look similar to the following screenshot.
Click OK to close the Project Properties dialog.
After configuring your project, build it by selecting , from the main menu. You then run the project using , .
On running the application, you should see a screen similar to the following (this is actually the static version of the application shown):
The preceding settings and procedures were carried out for the
default Debug configuration. To create a
Release configuration, select that
configuration before setting the Project Properties.