Documentation Home
MySQL Connector/C++ 1.1 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 285.1Kb
PDF (A4) - 286.0Kb


MySQL Connector/C++ 1.1 Developer Guide  /  Building Connector/C++ Applications  /  Building Connector/C++ 1.1 Applications on Linux with NetBeans

5.3 Building Connector/C++ 1.1 Applications on Linux with NetBeans

This section describes how to build Connector/C++ 1.1 applications for Linux using the NetBeans IDE. For general application-building information, see Section 5.1, “Building Connector/C++ Applications: General Considerations”. (These instructions have not been tested for Connector/C++ 8.0.)

  1. Create a new project. Select File, New Project. Choose a C/C++ Application and click Next.

  2. Give the project a name and click Finish. A new project is created.

  3. In the Projects tab, right-click Source Files and select New, then Main C++ File....

  4. Change the filename, or simply select the defaults and click Finish to add the new file to the project.

  5. Now add some working code to your main source file. Explore your Connector/C++ installation and navigate to the examples directory.

  6. 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++.

  7. At this point, NetBeans shows some errors in the source code. Direct NetBeans to the necessary header files to include. Select File, Project Properties from the main menu.

  8. In the Categories: tree view panel, navigate to Build, C++ Compiler.

  9. In the General panel, select Include Directories.

  10. Click the ... button.

  11. Click Add, 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 Select. Click OK.

  12. Click OK 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++ dynamic or static library. The project settings are slightly different in each case, because you link against a different library.

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.

  1. Set the project to link the necessary library file. Select File, Project Properties from the main menu.

  2. In the Categories: tree view, navigate to Linker.

  3. In the General panel, select Additional Library Directories. Click the ... button.

  4. Select and add the /usr/local/lib directories.

  5. In the same panel, add the library file required for static linking as discussed earlier.

  6. Click OK to close the Project Properties dialog.

After configuring your project, build it by selecting Run, Build Main Project from the main menu. You then run the project using Run, Run Main Project.

On running the application, you should see a screen that displays information like this:

Running 'SELECT 'Hello World!' AS _message' ...
        ... MySQL replies: Hello World!
        ... MySQL says it again: Hello World!

[Press Enter to close window]
Note

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.

Using the Static Library

To use the Connector/C++ static 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. (Remember, the MySQL client library is an optional component as part of the MySQL installation process.)

  1. Set the project to link the necessary library files. Select File, Project Properties from the main menu.

  2. In the Categories: tree view, navigate to Linker.

  3. In the General panel, select Additional Library Directories. Click the ... button.

  4. Select and add the /usr/lib and /usr/local/lib directories.

  5. In the same panel, add the two library files required for static linking as discussed earlier.

  6. Click OK to close the Project Properties dialog.