I have been playing around with Intel’s open source TBB (Threading Building Block) recently.The default download includes all the sources that can run on Windows , Linux or Mac OS X. The linux version however, builds using the shell by default and does not support any IDE’s (the Windows version can be built using Visual Studio 2003 or 2005). Even though running TBB applications under any Linux IDEs is not all that different comparing to doing the same under Windows, I found that there were not many tutorials on the Internet on how to do this. So here, I will show you how to setup KDevelop and Code::Blocks for you TBB development and debugging.
KDevelop is a powerful multi-language development IDE that comes as default package for the KDE environment (e.g. Kubuntu). For those who are using GNOME, it can be easily installed via apt-get install (Ubuntu).
The KDevelop IDE is one of the most feature-rich inegrated programming environments on Linux, but unfortunately it is not the easiest to get started due to its overwhelmingly large feature set. Here I will show you what I found the easiest way to set up a project that supports TBB, using the Automake project type.
The version of KDevelop I am using is 3.5.9. The commands might be slightly different in other versions, but the idea should be the same. To start a TBB application, use Automake project type (Projects -> New Projects, under C++ Automake Project, choose Empty Autotools Template.)
Don’t be surprised to see a few dozens of files being created, most of these files are used for program auto-configurations.
For all Automake projects, an active target is needed. So we will need to create an active target. By default, all the targets are configured within the right-hand-side split panels. The name of the active target will be compiled into the binary executable. In my example below, the target is named as tbbdev. In my example, I will use one of the stock program (sub_string_finder.cpp) that came with the TBB source code. It can be found in {TBB Source root}/examples/GettingStarted/sub_string_finder/
In order for the target application to find the shared library at runtime, we need to setup an environment variable LD_LIBRARY_PATH. The setting can be found at Project -> Project Options.
In the example given above, the TBB library source was extracted within my user’s root folder under tbb (/home/kwong/tbb/tbb20_020oss_src/), and the library I used is for 64 bit operating systems. Depending on whether it is debug build or release build, choose library path accordingly.
Next we need to configure the build target. The include paths are configured at the root project level (which is the parent to all configured targets).
the added directory should take the following format: -l{TBB installation root}/include/.
Then we will configure the target library path (this takes place at the active target level):
2
Note the syntax, the first part (-L) specifies the library path, and the second part (-l) specifies the library name. The actual library is called libtbb_debug.so.
That’s all the settings you will need to compile and run the sample program. Before you start debugging though, make sure that the current target is set to be built in debug mode (For some reason, the default build config does not support debugging and thus you can not set breakpoints within the IDE):
Alternatively, you can also change the compiler flags (CXXFLAGS) to -O0 -g3 (in prorject options).
After the above steps, you should be able to compile, debug and run the sample TBB program from within KDevelop.
As I suggested earlier, Kdevelop might not be the easiest to configure and run since it is mainly geared towards the more complex KDE applications. If you are so used to Microsoft Visual Studio IDEs, you might find Code::Blocks much easier to use.
Start Code::Blocks, and choose File -> New -> Project and choose Console Application. Again, we will use the sub_string_finder.cpp sample code. The library path/include path properties can be set either at the Workspace level (one workspace can contain multiple projects and the settings are inherited unless overwritten) or project level. Assume that we are configuring at the workspace level. Click and highlight the workspace, and choose from menu Project -> Build Options and click on the Linker settings tab. Add the libraries to be linked here:
Note that only the first entry was necessary for this particular project. As you can see from above, you can configure multiple library dependencies here easily. Now click on the Search directories tab, and set up the include path:
Now you can build and debug the application in Code::Blocks.