Archive | C++ RSS for this section

Build boost RegEx

I am using the boost library in the persistO ORM with the new C++ features. Everything was working good until I decided to use the ‘RegEx” library to search & replace text in a string. My assumption was that it will just work by adding the library link, like all other boost features were working but it didn’t. I searched the internet and found out that I will need to build the library with my compiler. I couldn’t find any good link to do it easily, except the link which gave a clue to right direction.

I needed the following steps from this article to get it fixed:

  1. Ran “Visual Studio Command Prompt” from tools folder in my VS installation as admin
  2. cd’ed to boost root
  3. Run bootstrap.bat from command line

It took 15-20 minutes for the compiler to compile the whole thing and at the end it generated the library files in:

<boost root>\stage\lib

The next change I required was to change the following libs name:

libboost_regex-vc-mt-1_49          ->   libboost_regex-vc110-mt-1_49
libboost_regex-vc-mt-gd-1_49     ->     libboost_regex-vc110-mt-gd-1_49

Then add the “\stage\lib” path to the project library path.


C++ user library path for Linux

I have just started to learn programming in C++ for Linux platform. I am using QT to create the shared library project and tried to link it with the QT GUI application. As I came from Windows platform, so I was assuming that I will compile the library and it will generate some (.a) file, just like the (.dll) file on Windows platform. But my first mistake was that I started with “Shared LIbrary” project and compiling it doesn’t generate a (.a) file and I didn’t know about the (.so) files. Well it took me quite a while to learn about it through googling but I was glade to finally fix the linking of static and shared linked library on Linux.
In the example below, I will be using the following library file name and path.

Library Name: libTestLogic
Library Extensions: (.a) for static library and (.so) for shared library
Library Path: /home/MyUser/TestPro/TestLogicProject

Static Library Reference in QT .pro file
Open the .pro file of QT GUI App and add following lines. It will be enough to use the static file:

INCLUDEPATH += /home/MyUser/TestPro/TestLogicProject
LIBS += -L/home/MyUser/TestPro/TestLogicProject -lTestLogic

Shared Library
Open the .pro file of QT GUI App and add following lines. This is same as static library:

INCLUDEPATH += /home/MyUser/TestPro/TestLogicProject
LIBS += -L/home/MyUser/TestPro/TestLogicProject -lTestLogic

then we need to open the “MakeFile” in the GUI app folder and find the line for “-rpath”. If it already has library path then add a “:” and the shared library path there. An example of this will be:

LFLAGS        = -Wl,-rpath,/home/MyUser/qtsdk2010/qt/lib:/home/MyUser/TestPro/TestLogicProject

This -rpath is passed to gcc to link the .so and .so.1 files.

Another option for shared library is to specify this library path in the That will make sure that we don’t have to modify the MAKE file every time when we reference our same shared library from more projects.

sudo /etc/

after adding the path to library on a new line in that file, save the file and running following command to configure the linker run-time bindings.

sudo ldconfig

Configure MySQL Database Driver for QT

I am working on a QT project on Ubuntu and I needed to use the MySql database driver for it. In previous versions of QT, it used to be the default installed library but with QT 2010.2 installation (4.6 and above), it is not the default installation. So, it requires to configure the MySql header files and then configure the QT to use the file. Here are the steps which worked for me.

1. First of all, we need to install the MySql Deveoper Libraries on Ubuntu. This will be required by QT to compile the MySql driver.

sudo apt-get install libmysqlclient15-dev

2. After this installation is successful. It will create the folder “/usr/incluce/mysql” in the Ubuntu installation and it will also install the lib files in “/usr/lib/mysql”. We will need this to compile the QT MySql driver:

cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r"

3. After this, just need to compile the QT code using the “QMYSQL” driver.