Relative RPath Settings with CMake

The run-time search path (rpath) defines paths to search for dynamic libraries when executing a program. It is a mechanism on Linux parallel to the LD_LIBRARY_PATH environment variable, which is another hint to find dynamic libraries. Usually, it is a good idea to make software which you built relocatable. This means that created binaries can be moved around and they still work after the location change. This includes the ability to still find the correct versions of dynamic libraries. One simple way to achieve this is by setting the rpath relative to the current location of the binary. In CMake this can be achieved like this: ...

February 16, 2012 · updated April 30, 2021 · 1 min

Using Dependency Tracking in Jenkins with CMake-based C++ Projects

If you are building multiple related software projects with a continuous integration server one important aspect is to be notified when changes in an upstream job break the build or tests for a downstream job. This involves knowing which exact build numbers of the upstream and the downstream job are involved. The Jenkins continuous integration server uses the notion of file fingerprints for this purpose. The upstream job is built by Jenkins and produces one or several so called artifacts, the results of the build process. The artifacts are archived by Jenkins and fingerprints (hash sums) for each artifact are created and stored along with the build number of the job. When the downstream job starts to build it downloads the (most recent) artifacts from the upstream job and uses them for its purposes, i.e. building and running the own source code. By comparing the fingerprints of the downloaded artifacts with the stored fingerprints Jenkins knows which version of each upstream job was involved in a build and can track which upstream build number broke the downstream job. Jenkins will only issue notifications if this fingerprinting mechanism is properly configured, triggering a build after another is not sufficient to receive these notifications. Moreover, the Blame Upstream Commiters plugin needs to be used and enabled for each downstream job or the global property hudson.upstreamCulprits (will this ever be renamed?) needs to be set. ...

July 31, 2011 · updated April 30, 2021 · 6 min

Gcov Coverage Reports in Jenkins

I am currently evaluating the applicability and limitations of the Jenkins continuous integration server for C++ development. Besides several limitations which are mainly caused by the complexity of C++, Jenkins provides a solid basis for continuous integration of C++ projects. One thing which I was not happy with so far was the missing integration of open-source coverage tools for Linux. Here, Gcov can be used to generate more or less precise coverage reports for projects compiled with GCC. Unfortunately, Gcov itself does not provide tools to export the results in any common or even nicely readable format. Until now, the only working solution I found was to use the Gcov front-end LCOV to generate a HTML report. This report is nice to read but it cannot be tracked by Jenkins with the drawback that no trend report for the code coverage can be generated. Nevertheless, I’ve wrapped the creation of such a HTML report in a CMake function and worked with it so far. ...

April 9, 2011 · updated April 30, 2021 · 2 min

Evaluation of Default Arguments in Python

Today I stumbled upon a very subtle problem with default arguments in python. I noticed that loading a python module already instantiated one of my classes even though I could not find an installation of this class. In the end it turned out to be a default argument for a function: def foo(arg=MyClass()): pass As I am currently programming a lot in C++ this did not look suspicious to me. But from python’s point of view it absolutely makes sense that the default value for arg is already constructed at module load time and not only on a call to that functions. Moreover it is important to remember that this default argument is constructed only once for all calls to a function as stated here. ...

January 19, 2011 · updated April 30, 2021 · 1 min

Boost bind and smart pointers

I’ve seen this several times causing troubles: boost::shared_ptr<Foo> p(new Foo); boost::thread t(boost::bind(&Foo::method, p.get())) This prevents the livecycle management of shared_ptr or any other smart pointer to be effective in the thread. Hence, p may get destructed even though the thread is still active. Boost bind can handle smart pointers, so instead use the smart pointer itself as the instance argument for bind: boost::thread t(boost::bind(&Foo::method, p))

January 9, 2011 · updated April 30, 2021 · 1 min

bash: Home Directory Not Replaced With Tilde (~)

After switching my computers to Arch Linux, reusing the existing home directories, I had the problem that the bash did not replace the user’s home directory with the tilde character (~) in the prompt. The solutions for this problem is easy: somewhere in the bash-internals a check tests whether the output of pwd matches the contents of $HOME. $HOME, in turn, is filled from the user definition in /etc/passwd. pwd always returns the current working directory without a trailing slash, but the entry for my user in /etc/passwd contained a trailing slash. Removing this slash from the file solves the problem and the prompt uses ~ again for the home directory. ...

December 30, 2010 · updated April 30, 2021 · 1 min

Ignoring Warnings from System Headers

Compiling C and C++ code with the highest warning levels is a good practice and helps spotting potential errors. For GCC the flags -Wall -Wextra will generate a lot of useful warning messages about unused parameters etc. Unfortunately, this is not the common practice and often the own compiler settings concerning the warning level results in dozens of warnings from system headers on which the own code relies, making it impossible to spot warnings from your own code in the endless mass of console output. ...

August 20, 2010 · updated April 30, 2021 · 1 min

Unused Parameters in C++

Just some quick thought on how to handle compiler warnings about unused parameters in C++ code. While these warnings are helpful most of the time, sometimes you simply have to ignore a parameter that is required by an interface definition. Then you got three solutions to remove the warning: Change the compiler flags. The worst solution. In other cases these warnings are really helpful. Generally I really like to compile with the highest warning level. Most of the warnings (at least for GCC) really have something to tell. ...

August 9, 2010 · updated April 30, 2021 · 2 min

CMake: installing headers and preserving the directory structure

CMake doesn’t provide a dedicated way to install header files (except for mac). What I wanted to do was to install all headers of my project using the same directory structure as in the source tree. This isn’t as easy as it sounds. Assume you have a list of header files: SET(HS folder/test.h folder/other/test2.h) A simple call to INSTALL doesn’t preserve the folder structure: INSTALL(FILES ${HS} DESTINATION include) This results in all files being directly under $prefix/include. ...

May 31, 2010 · updated April 30, 2021 · 1 min

Using googlemock with the Boost Test Library

googlemock is a framework that allows generating mock objects for unit tests. I’ve decided to use this framework as it looks wells designed and maintained. The default is to use googlemock with Google’s unit testing framework googletest, but as I was already using the Boost Testing Library, I was searching for a solution to use googlemock in Boost Test. Fortunately this isn’t to hard to accomplish. You only have to create a TestEventListener that forwards all results supplied by googletest to the Boost Testing Framework: ...

April 13, 2010 · updated April 30, 2021 · 2 min