[Insight-users] Problem with debugging code using ITK, cmake, and qt creator

Matt McCormick matt.mccormick at kitware.com
Mon Oct 1 11:57:09 EDT 2012


Hi Andreas,

General instructions for using QtCreator with CMake can be found here:

  http://doc.qt.digia.com/qtcreator-2.4/creator-project-cmake.html


To perform debugging, it is best to have debugging symbols compiled
into the binaries.  For GCC, this means passing the "-g" flag when
compiling, which is set by default with CMAKE_BUILD_TYPE=Debug or
CMAKE_BUILD_TYPE=RelWithDebInfo.  For CMAKE_BUILD_TYPE=RelWithDebInfo,
the "-O2" optimization flag is also passed to the compiler.  So, the
program can be debugged, but it may bounce around in non-trivial ways
or some variables may be optiimized out.


A good workflow takes advantage of CMake's out-of-source build
capabilities.  That is, during development, it is typical to work with
one source tree but two build trees.  One build tree will be built
with CMAKE_BUILD_TYPE=Debug and the other with
CMAKE_BUILD_TYPE=RelWithDebInfo or CMAKE_BUILD_TYPE=Release.  When you
need to do debugging, work with the Debug binaries.  In this case, you
will have two build of ITK and two build of your project, each using
the same CMAKE_BUILD_TYPE.

Hope this helps,
Matt

On Mon, Oct 1, 2012 at 3:17 PM, Merrem, Andreas
<a.merrem at dkfz-heidelberg.de> wrote:
> Hello,
>
> I am working with a program that uses ITK functions and would like to debug it with qt creator. Running it works fine, however, I can't use the debugger and set break points.
>
> I added a custom build step to the project with the following information:
>     *
>       Name
>           o
>             cmake
>     *
>       Command
>           o
>             /usr/bin/cmake
>     *
>       Working directory
>           o
>             $BUILDDIR
>     *
>       Commandline arguments
>           o
>             -DCMAKE_BUILD_TYPE=Debug .
>
> When I tried to execute this build step, it first didn't find ITK, when I added the line
>
> SET (ITK_DIR /home/merrem/ITK/build) (i.e. the directory with the ITKConfig.cmake file)
>
> to the CmakeLists.txt file, it apparently managed to find ITK, but didn't really like what it found, and told me:
>
> Running build steps for project VascuSynth...
> Starting: /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug
> CMake Error at /home/merrem/ITK/itksource/CMake/ITKModuleAPI.cmake:50 (message):
> No such module: "IN"
> Call Stack (most recent call first):
> /home/merrem/ITK/itksource/CMake/ITKModuleAPI.cmake:25 (itk_module_load)
> /home/merrem/ITK/itksource/CMake/ITKModuleAPI.cmake:30 (_itk_module_config_recurse)
> /home/merrem/ITK/itksource/CMake/ITKModuleAPI.cmake:67 (_itk_module_config_recurse)
> /home/merrem/ITK/build/ITKConfig.cmake:74 (itk_module_config)
> /usr/share/cmake/Modules/FindITK.cmake:78 (INCLUDE)
> CMakeLists.txt:14 (find_package)
>
> -- Configuring incomplete, errors occurred!
> Exited with code 1.
> Error while building project VascuSynth
> When executing build step 'cmake'
>
>
> How can I use the debugger on programs using ITK functions? I don't want to look into the ITK functions themselves, so is there a way to avoid rebuilding ITK in the debug mode? If not, how do I link everything once I built ITK in debug mode so that I can use my programming environment the normal way (click on debug if I want to debug, click on run if I want to run, not getting tangled up in a spider web of linking problems and having to change everything each time I want to do something)? Can I do that using only one cmake file?
>
> I would appreciate your help very much,
>
> Andreas
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list