[Insight-users] [insight-users] Eclipse setup : debug, viewing sources and correct project tree

Mike Jackson mike.jackson at bluequartz.net
Tue Mar 9 20:50:50 EST 2010


>> On Tue, Mar 9, 2010 at 5:14 PM, Antonin Perrot-Audet
>> <antonin07130 at gmail.com>  wrote:
>>
>>>
>>> Hello,
>>> After spending some time configuring ITK with Xcode, I figured out that
>>> the
>>> code completion was not working, and as I'd like to have a confortable
>>> environment to code (I like to have a graphical debugger ... etc...), I
>>> decided to give Eclipse a try... But :
>>>
>>> *I have (much) trouble configuring ITK with Eclipse CDT :*
>>>
>>> 1)    First of all, when I import the project I get a lot of warnings :
>>> "
>>> Invalid project path: Include path not found
>>>
>>> (/Users/antonin/[...]/Programming/ITK/Antonin/TrainEclipse/bin/(framework).
>>> TRAINPROJ-
>>> "
>>> 2)    I can "build all", and get a nice executable in
>>> /TrainEclipse/bin/src/
>>> which works perfectly when executed via a terminal, BUT, I cannot use the
>>> hammer icon : build the active configuration for the active project...
>>> 3)    I cannot debug, Eclipse seems not to find the executable it just
>>> made... The debug configuration is almost empty, and it tells me that
>>> there
>>> should not be an "@" in the configuration name...
>>> 4)    the generated project doesn't show my sources, it seems like the
>>> project root is the "build" directory, and my sources are not in the
>>> project
>>> tree
>>>
>>> Here is how I organized my sources : (there is only main.cxx for testing
>>> purpose)
>>>
>>> TrainEclipse
>>> |
>>> |CMakeLists.txt //content described in CMakeLists I
>>> |
>>> |
>>> |--src
>>> |    |main.cxx
>>> |    |CMakeLists.txt //content described in CMakeLists II
>>> |
>>> |--lib
>>> |    |CMakeLists.txt //content described in CMakeLists III
>>> |
>>> |--build
>>> |    |(Cmake generated files for the eclipse project with the
>>> .project...etc...)
>>> |
>>>
>>> Here are my CMakeLists :
>>>
>>> *CMakeLists I :*
>>> "
>>> # CmakeList.txt in root of project : structure of project (OMG this is
>>> heavy)
>>>
>>> cmake_minimum_required(VERSION 2.6)
>>>
>>> # Name of the project
>>> PROJECT(TRAINPROJ)
>>>
>>> # Project structure
>>> # add_subdirectory (lib) for now, no lib...
>>> add_subdirectory (src)
>>> "
>>>
>>>
>>>
>>> *CMakeLists II :*
>>> "
>>> #CmakeList.txt from the src directory
>>>
>>> # Find ITK.
>>> FIND_PACKAGE(ITK REQUIRED)
>>> IF(ITK_FOUND)
>>>   INCLUDE(${ITK_USE_FILE})
>>> ENDIF(ITK_FOUND)
>>>
>>> # Make sure the compiler can find include files from our lib folder
>>> library(ies).
>>> INCLUDE_DIRECTORIES(${TRAINPROJ_SOURCE_DIR}/lib)
>>>
>>> # Add binary called "main" that is built from the source file "main.cxx".
>>> # The extension is automatically found.
>>> ADD_EXECUTABLE(main main.cxx)
>>>
>>>
>>> # Link the executable to the library(ies). (add lib after main)
>>> TARGET_LINK_LIBRARIES(main ITKNumerics ITKIO itkgdcm itkvcl itkvnl
>>> ITKAlgorithms ITKBasicFilters ITKCommon )
>>> "
>>>
>>>
>>>
>>> *CMakeLists III :*
>>> "
>>> # CmakeLists.txt in lib dir
>>> # Adds a library called lib (liblib.a under Linux) from the source file
>>> lib.cpp
>>> # ADD_LIBRARY( lib lib.cpp )
>>> "
>>>
>>>
>>>
>>> And Here is how I generated the project for eclipse :
>>>
>>> in a terminal, from the build directory :
>>> "
>>> cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../
>>> "
>>> I simply imported the project in eclipse, specifying the /build folder
>>> where
>>> the .project is.
>>>
>>>
>>>
>>> Any help would be greatly appreciated,
>>>
>>> Regards,
>>>
>>> Antonin
>>>
>>> _____________________________________
>>> 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.html
>>>
>>> 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
>>>
>>>
>>>
>
> Thank you for your succinct answer, you mean that I should try the Unix
> Makefile Generator and generate a project with that?
> I tried that already, with the same type of problem : Eclipse was only able
> to produce an executable, and I could not figure out how to use it for IDE
> tasks (editing sources with a correct project tree, debugging... etc):
> It was giving me an environment, from where to click build all, and get an
> executable (basically, the same as typing "make" in a terminal). I may not
> have been clear with my expectations : I would like the eclipse project to
> list my sources, and give me the possibility to edit them, and debug them.
> Are my CMakeLists.txt wrong? is it the folder build from where I type the
> command
>
> cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../
>
> which is wrong?
>
> regards,
>
> Antonin
>

How _I_ use CDT is with "Makefiles" generated from CMake. I do NOT
actually have CMake generate Eclipse Project files. So the CMake
command on a CLEAN build directory is this:

cmake ../

That will generate Makefiles for your project. You can now run "make"
from a command like and should be able to build and execute your
program.

 Now launch Eclipse. On the left side of the Eclipse Window should be
a "C++ Projects" view. If it is NOT there then you can go to
"Window->View->C++ Projects".
  This is all painstakingly laid out on the CMake WIki that I sent.
Down towards the bottom of that Wiki page is a section about
"Automatic Discovery of Include directories (Optional, but handy) ".
Make so you follow those instructions as it will set up your project
so that Eclipse can automatically find all the include files from ITK
and your own project.

When you have finished creating your project in Eclipse you should be
able to see your top level project folder in the C++ Projects view on
the left side of the Eclipse Window. From there you can navigate
through your project and double click on files to open them up in the
C++ editor.

Couple of things that also might help. I would find the option to
"Build Automatically" and turn it OFF. For C++ it does not make sense
and just burns up time and slows things down. With a "makefile"
project there will only be a single configuration. There is NO
debug/release. It is dependent on how ever you had CMake configure
your project.

Others may have their own opinions on how to setup Eclipse with CMake
but this has been working for me for about 3 or 4 years now.

 Hope that helps.
--
Mike Jackson.


More information about the Insight-users mailing list