Difference between revisions of "Slicer3::Eclipse"
(→Creating an Eclipse Project for Slicer3:: typo in dir name) |
|||
Line 102: | Line 102: | ||
'''Step 6:''' Enter the make command we want to use. Notice that we specified four jobs (to build faster) and specified the location to use as the current directory for the build: | '''Step 6:''' Enter the make command we want to use. Notice that we specified four jobs (to build faster) and specified the location to use as the current directory for the build: | ||
− | :'''make -j 4 -C Users/dot/Projects/slicers/trunk-012210/Slicer3-build''' | + | :'''make -j 4 -C /Users/dot/Projects/slicers/trunk-012210/Slicer3-build''' |
'''Step 7:''' In the same pop-up window, enter the build directory again in the "Build location" dialog (same pathname as you just entered above in step 6). Now you can click OK to accept these entries. Eclipse should start building the project right away. You can see the C++ compilations go by in the "Console" tab at the bottom. We are using Eclipse to fire off the makefile built by cmake. This means we can still go outside Eclipse and type "make" by hand anytime. Eclipse just knows how to fire off the make when necessary. | '''Step 7:''' In the same pop-up window, enter the build directory again in the "Build location" dialog (same pathname as you just entered above in step 6). Now you can click OK to accept these entries. Eclipse should start building the project right away. You can see the C++ compilations go by in the "Console" tab at the bottom. We are using Eclipse to fire off the makefile built by cmake. This means we can still go outside Eclipse and type "make" by hand anytime. Eclipse just knows how to fire off the make when necessary. |
Latest revision as of 13:37, 21 December 2012
Home < Slicer3::EclipseContents
Howto Setup Eclipse – Slicer3 Development Environment:
First download your Eclipse version (e.g. from http://eclipse.org/downloads/ )
This description is based on Eclipse Helios:
eclipse-cpp-helios-linux-gtk.tar.gz
After checking out the sources and building 3D Slicer
CASE: the classic way (Slicer 3.6)
svn co http://svn.slicer.org/Slicer3/branches/Slicer-3-6 Slicer3
./Slicer3/Scripts/getbuildtest.tcl
you will find 3 folders in your directory
Slicer3 (3D Slicer source) Slicer3-lib (Dependencies source+binary) Slicer3-build (3D Slicer binary)
Go to the 3D Slicer binary directory and generate your eclipse project files
cd Slicer3-build cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../Slicer3
CASE: using Superbuild (Slicer 4.0)
svn co http://svn.slicer.org/Slicer4/trunk Slicer4
mkdir Slicer4-SuperBuild cd Slicer4-SuperBuild cmake -DSlicer_USE_KWWIDGETS:BOOL=OFF -DSlicer_USE_PYTHON:BOOL=OFF -DSlicer_USE_QT:BOOL=ON -DSlicer_USE_PYTHONQT:BOOL=OFF ../Slicer4/SuperBuild make cd ..
You will find 2+1 folders in your directory
Slicer4 (3D Slicer source) Slicer4-SuperBuild (Dependencies source+binary) Slicer4-SuperBuild/Slicer-build (3D Slicer binary)
Go to the 3D Slicer binary directory and generate your eclipse project files
cd Slicer4-SuperBuild/Slicer-build cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../../Slicer4
You will get 2 files
Slicer3-build/.project Slicer3-build/.cproject
Import the created project file into Eclipse
1. Import project using Menu File->Import 2. Select General->Existing projects into workspace: 3. Browse where your build tree is and select the root build tree directory. Keep "Copy projects into workspace" unchecked. 4. Click "Finish"
You get a fully functional eclipse project
- Add a -j<cores> to your make command (Properties->C/C++MakeProject)
- Under "Window->Preferences->General->Editors->Text Editors" please check "Insert spaces for tabs"
Revised Howto Setup Eclipse to build/edit the Slicer3 Development Environment (Eclipse 3.5)
Installing Eclipse:
These instructions have been tested with Eclipse editions including "Ganymede" (3.4), "Galileo" (3.5), and "Helios" (3.6), but this should work with any Eclipse Version 3.3 or higher. The easiest way to get started is to select an eclipse distribution which already includes CDT, the C++ development tools, integrated. This is available from http://www.eclipse.org/downloads. Download Eclipse and unpack the downloaded archive to the destination you want. You start Eclipse by executing ./eclipse from the base directory of your eclipse installation.
Configure Eclipse:
As computers become more powerful, it is less necessary to adjust the runtime parameters of Eclipse, but some tweaking hints are listed on the original Eclipse page here.
Modules for Eclipse you need:
As mentioned above, it is easiest to start with an integrated Eclipse containing CDT already. However these prebuilt configurations were available only in 32-bit versions the time of this writing. So some users who need full 64-bit versions may need to configure Eclipse by hand. If this is the case, the CDT tools can be integrated by hand into Eclipse. If you want to use Eclipse to connect to Slicer's SVN repository and compare versions, update source, etc. (highly recommended), then you'll need to add the Subclipse package to Eclipse. Please see the original Eclipse Wiki page here for instructions adding these packages into Eclipse. The URLs for these two Eclipse plug-ins are:
- CDT – C++ Environment: http://www.eclipse.org/cdt
- Subclipse: http://subclipse.tigris.org/install.html
Creating an Eclipse Project for Slicer3:
Step 1: Build Slicer3 outside of Eclipse using getbuildtest.tcl or your alternate build system of choice.
For this discussion, lets assume "/Users/dot/Projects/slicers/trunk-012210" contains the Slicer3* directories. So we could go into /Users/dot/Projects/slicers/trunk-012210/Slicer3-build and type "make".
Step2: Create a new C++ project in Eclipse. Yes, it is a Makefile project. Uncheck "Use default location". Select the Browse function and navigator to the Slicer3 source directory for the Eclipse project location. In our example case, we would select "/Users/dot/Projects/slicers/trunk-012210/Slicer3". In my version of Eclipse (Galileo), it now has more options for the Project. I selected "Makefile Project" and specified "Empty Project".
Step 3: Click "Finish" to create the project. We will edit the project info later to get it really working. The C++ indexer may take a few minutes the first time it is consuming the whole Slicer tree during this step. After this, it is pretty fast.
Step 4: You should see the project in the Explorer tab on the left now. Select then right click the project we just created. Mine was called "Slicer-trunk" and edit the project properties (the entry at the very bottom of the pop-up menu). The project properties dialog should pop up.
Step 5: Select the "C/C++ Build" branch of the tree diagram on the left of the dialog. In "Builder Settings", uncheck "Use default build command" .
Step 6: Enter the make command we want to use. Notice that we specified four jobs (to build faster) and specified the location to use as the current directory for the build:
- make -j 4 -C /Users/dot/Projects/slicers/trunk-012210/Slicer3-build
Step 7: In the same pop-up window, enter the build directory again in the "Build location" dialog (same pathname as you just entered above in step 6). Now you can click OK to accept these entries. Eclipse should start building the project right away. You can see the C++ compilations go by in the "Console" tab at the bottom. We are using Eclipse to fire off the makefile built by cmake. This means we can still go outside Eclipse and type "make" by hand anytime. Eclipse just knows how to fire off the make when necessary.
At this point, Eclipse will be able to compile Slicer3 but not able to run Slicer3 from the execute project icon, yet.
Step 8: Quit Eclipse and setup a shell which has the Slicer3 environment defined in the shell before running Eclipse inside the shell. In Linux or Mac, this can be done using a Bash shell script found in the Slicer3 build directory (/Users/dot/Projects/slicers/trunk-012210/Slicer3-build/bin/Slicer3Setup.sh in our example). A shortcut can be created, using a shell alias, similar to the following example. I define this in my list of aliases auto created during login:
- alias trunk='source /Users/dot/Projects/slicers/trunk-012210/Slicer3-build/bin/Slicer3SetupPaths.sh; ~/Desktop/eclipse/eclipse '
Continuing with Debugging under Eclipse
At this point, you should be able to build Slicer using Eclipse and run Slicer from inside Eclipse. If you want to debug Slicer interactively under Eclipse, there is a bit more configuration to perform. Please continue with the debugging instructions found below.
Debugging with Eclipse Instructions
There are a few key things about interactive debugging under Eclipse that once are done right, then it just works:
- build Slicer totally first the normal way, either with cmake or getbuildtest.tcl.
- Create the project in Eclipse by referring to the makefile and entering an external make command line
Assuming that Slicer is building under Eclipse, we'll take off from this point on:
Understanding Slicer's startup process
The executable ./Slicer3-build/Slicer3 is not the real program, instead it is just a "launcher". This executable sets up a bunch of paths and environment variables, then launches the real executable. The "real" Slicer3 program is stored in: ./Slicer3-build/bin/Slicer3-real. So when we are asking Eclipse to run Slicer under the debugger, we really want Eclipse to startup and attach to an instance of "Slicer3-real".
Step 1: There is a script in ./Slicer3-build/bin/Slicer3SetupPaths.sh or ./Slicer3-build/bin/Slicer3SetupPaths.csh which sets up the same paths as the launcher. If we run this script in a shell window (on Mac or Linux), then run eclipse from the same shell, we will have the environment defined. This is how to try it the first few times, but there is a cleaner way we will try after we know debugging is working. So if you are on either a Mac or Linux, open a shell and source this setup script, please.
Then in the same shell, start eclipse. It will be something like this:
- % source ./Slicer3-build/bin/Slicer3SetupPaths.sh
- % ~/Desktop/eclipse/eclipse &
Step 2: Then in the Eclipse window, open the Project/Properties by right-clicking on the Project Explorer entry for your Slicer build. Then select the "Run/Debug Settings" entry. We want to set the executable to point to "Slicer3-real" instead of "Slicer3". This plus running the script in the shell Eclipse was started from *may* be enough to get the debugger started on Slicer.
If you are using a Mac, shared library loading can be slow and gdb can timeout during Slicer's loading process. I have not had this problem on Linux and can't comment on Windows since I have not tried it in under Windows. It was helpful on Mac under Leopard and Snow Leopard to increase the default timeout allowed by Eclipse if your Mac needs a bit more time to get everything initialized when first beginning a debugging session.
Note to Snow Leopard users
In the Summer of 2010, we found moving to Snow Leopard caused debugging to stop working. The newest (nightly build) of Eclipse was needed to get breakpoints to actually force the program to stop again. Debugging worked without tweaking Eclipse for systems running Tiger and Leopard. However, the 64-bit only mode of Snow Leopard meant a 64-bit Eclipse is needed for debugging. It is expected that these issues will be resolved in the release version of Eclipse 3.6 (Helios). Do remember that debugging only works using a 64-bit version of Eclipse on Snow Leopard (because the build is now a 64-bit build.)
Also, there is a known bug where Eclipse/GDB cannot insert breakpoints into the code is they were defined before program execution began, so the debugger doesn't stop when it comes across a previously-defined breakpoint. For now, the work-around for this is to invoke Slicer, so the Slicer GUI is constructed. Then once execution has started, use the Eclipse interface to set the desired breakpoints and continue with the debugging. This will work for debugging cases not involved in the initial GUI construction.
Old description from 2008
PreRequirements for compiling Slicer3:
Installing Eclipse:
I installed Eclipse 3.3 M4, but this should also be applicable with Eclipse Versions under this. Download Eclipse from www.eclipse.org and unpack the downloaded archive to the destination you want. You start Eclipse with ./eclipse from the base directory of your eclipse installation.
Configure Eclipse:
To get Eclipse handling these big source packages in a good manner it is good to tweak a little the properties of the eclipse startup. First it is very advisable to use Eclipse with JRE 1.5. Download it from [1] and put it in your project folder (or elsewhere). In addition I increased the size of the memory Java can use with the lower bound switch -Xms and the upper bound -Xmx.
So my Eclispe command looks like this: ./eclipse -Xms64m – Xmx512m -vm /<path to your jre base-directory>/bin/java
Because sun only offers a java JRE for AMDX64 and not for Xeon CPU's it is also possible to use the JRE from BEA jorckit. This should be faster but also a little less stable (I didn't feel that something was unstable!)
Modules for Eclipse you need:
Before integrate the source-code into Eclipse we need two separate modules.
- CDT – C++ Environment: http://www.eclipse.org/cdt/downloads.php
- SubClipse: http://subclipse.tigris.org/install.html
I use right now CDT 4.0 - nightly build which is much more feature rich then 3.1. On the other Hand this is still under development and though not stable in any situation.
- To install these Modules, start Eclipse and go to Help->Software Updates->Find And Install
- Click on “Search for new features to install” and then on “Next”:
- Now click the “New Remote Site...” Button and insert the appropriate informations in the input fields.
- For CDT this should look like this:
- For SubClipse:
After adding these to module Site just click on the “Next” Button and Install both items.
You will be prompt to restart Eclipse. After the restart you're ready to get the sources into Eclipse.
Creating Project and getting the Source-Code for it:
Now that you have setup eclipse we can focus an getting the code and compile it. One of the disadvantages of eclipse is the inability to use Cmake and CmakeLists.txt files directly. So some manual configuration is still necessary. But hopefully the Eclipse on Linux Project will close this gap in the future. Go to the na-mic.org Slicer3-Development website and create for each listed application a new project in Eclipse. For CVS based projects create a new CVS-Checkout-Project and for SVN the SVN counterpart. Then to checkout the source select the branch or the head sources and create a “Standard C++ Makefile Project”. (right now it is recommend to use for tcl and tk the 8.4 branch, because till now VTK, KWWidgets and ITK are not modified to match tcl/tk 8.5) Configure all projects in the sequence as stated above. All projects besides Cmake, VTK, ITK, KWWidgets and Slicer3 itself are autoconf/ configure based application. For tcl/tk it is necessary to change the default source path to unix.
- Right-Click on the project folder
- click on properties (or just press Alt+Enter)
- then at C/C++ Make Project
- click on “Workspace...”
- select the unix folder from tcl or tk
Compile the projects:
After successfully configuring all projects eclipse should start automatically building the application. If this is not the case, right click on project and select “Build Project” and see how the project is compiling.