Repository navigation
eclipse
There are several methods to setup eclipse:
- using the CMake-eclipse-generator and importing the result into eclipse,
- or creating & configuring a project manually.
The easiest way to create an eclipse project is by using cmake.
If the source code is not already checked out, follow the instruction in the section Get the Source Code.
Then create a build directory for the debug version, e.g. at ~/Devel/CFS_BIN/build_debug (if it's not already created).
The created build directory will be called <build> in the following!
Go to <build> and configure the project choosing the CMake extra generator Eclipse CDT4 along with your main generator Unix Makefiles and debug options, e.g type
cmake -G "Eclipse CDT4 - Unix Makefiles" -DDEBUG=ON -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j1 <source>
You may use other configuration options (-D on the command line) or change them via running ccmake . in the <build> directory. In -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-jx replace x with the number of cores you want Eclipse to use when building the project. Note that that for the very first build, you might need to compile cfsdeps manually from the shell using one core: In <build> run
make cfsdeps
DEBUG=ON is necessary for the debugger to work!
The Eclipse CDT4 generator creates the files .cproject and .project in the <build> directory, which can be used to import the project into eclipse.
Now you need to import the project in eclipse and configure the indexer by:
- Open eclipse and import the project File => Import => General => Existing Project into workspace, click next and Select root directory =>
<build>, click Finish. - Exclude binary and library folders from indexing: (issue @eclipse2020)
- open project properties by selecting the project (left hand panel) and Project => Properties, right click, or Alt+Enter
- choose C/C++ Project Paths, click the Source tab, and select the Line Exclusion Filter
- choose Edit and add
cfsdeps,cmake_modules,ctest_scripts,Testsuite
- Include shared library headers: (issue @eclipse2020)
- in project properties, C/C++ Project Paths select the tab Path Containers choose Add...
- mark Discovered scanner configuration container, click Next and Finish
- Rebuild the index by Project => C++ Index => Rebuild
- set spaces instead of tabs in the eclipse editor to comply to the CFS++ coding style:
- Window => Prefereces => C/C++ => Code-Style => Formatter and create profile.
- Click New.. and name your profile (e.g. openCFS)
- Under Indentation -> General settings choose as tab policy identation only and for identation size 2
- Hit Apply and Ok and choose your newly created profile and click Apply and Close
- Select File => New => Makefile project with existing code from the menu.
- Nothing else than Makefile project with existing code will work! Same for Import, don't do it!
- Fill in the Project Name.
- Enter the path to the source folder of the existing working copy under Existing Code Location.
- Select Linux GCC as the toolchain. Take care! The default option might be the cross compiler which we don't want!
- With Eclipse Mars your only option is "Finish" now. Note that the indexer immediately starts with a default configuration!
- Proceed with configuring the project (next section).
See above why it is important to setup the indexer properly - otherwise Eclipse becomes unusable. By default all code within the project will be indexed. If this is the real project root this includes all build directories - which is too much for the indexer. Therefore the "official" project root is the "source" directory and other stuff is linked.
- Right-Click the newly create project and select Properties.
- In the left pane of the project properties window navigate to "C/C++ General" => Paths and Symbols.
- Under Source Location is already one entry, but the source folder is meant!
/''Project Name''- In Source Location press the Link Folder button and activate Link to folder in the file system (in the Advanded dialog)
/your_project/cmake_modules
/your_project/share
/your_project/cfsdeps
/your_project/ctest_scripts
/your_project/root - where root is a manually created directory with a symbolic link: ln -s CMakeLists.txt root/-
to include
/your_project/includewith thedef_use_*.hh.infiles it might be necessary to link the directory to another directory with a name likedef_use_includeand add this to your project. -
For many systems problematic is to add
debug/includeas indexing boost might kill the indexer. You might want to try
debug/include- If you get the error folder already exists the project was not created in the source directory.
- If you still get the error folder already exists, even though the project was created in the source directory:
- Go to the source directory and delete the hidden files .project and .cproject and the folder .settings
If Eclipse's content assitance (F3) and auto-completion is too slow:
- Remove the inclusion of debug/include
- If you have never built CFS++ from this working copy, do so now using [wiki:CMake].
- Select Project => Properties from the menu.
- In the left pane of the project properties window select C/C++ Build.
- In the right pane, on the Builder Settings tab enter the path to your Build directory (e.g. debug) via File system....
- Make sure the Generate Makefiles automatically option is off.
- In the Beaviour tab:
- Change the Build target from all to cfsbin
- Enable parallel builds
- disable Stop on first build error
- You can build cfs via ctrl-B. This is also important for debugging!
At first startup Eclipse asks for a location, where its workspace should be stored. The default location is $HOME/workspace. Then activate the option Use this as the default and do not ask again, because you only need one workspace, usually.
In some situations it can make sense to use several workspaces.
In order to follow the CFS++ Style Guide the default settings need to be adapted. To make Eclipse use this convention,
- open the Preferences window by selecting Windows => Preferences from the menu. In the left pane navigate to General => Editors => Text Editors.
Then change these settings in the right pane:
- Displayed tab width: 2
- Inset spaces for tabs: yes
- activate Show whitespace characters and use configure visibility to show everything we do not want: Trailing space, Tab, Carriage Return
- If you use Eclipse's code formatter, you additionally have to adjust this: Go to C/C++ => Code Style => Formatter and select an appropriate profile. Then Click "Edit..." and change the following settings:
- Tab policy: Spaces only
- Indentation size: 2 Then type a new profile name (built-in profiles cannot be changed) and click OK.
Do not remove trailing spaces.
Because CFS++ is a large project (in terms of lines of code), the default memory size of Eclipse may not be sufficient. You have to edit the file eclipse.ini in the installation directory in order to increase the maximum amount of memory used by Eclipse:
--launcher.XXMaxPermSize
256m
-XX:MaxPermSize=256m
-Xms128m
-Xmx1024m
-
MaxPermSize: maximum size of permanent memory (for executable code); default: 256M; needs to be increased only very rarely -
Xms: minimum size of heap (for data); default: 40M; when used for CFS++ hacking, Eclipse always needs > 100M, so 128M is recommended -
Xmx: maximum size of heap (for data); default: 384M; default value is too low for CFS++ hacking (Code indexer fails, etc.), so choose depending on the amount of RAM in your computer
You can also set JVM args via the command line to increase the heap size
via the option -Xmx2048m in the startup command, e.g.
eclipse [normal arguments] -vmargs -Xmx2048m [more VM args]
In order to use Eclipse for coding in CFS++, you need to install some plugins. To do just that, choose "Help => Install New Software..." from the menu. In the Install window select the Juno software site in the field "Work with:".
Eclipse does not come with a built-in XML editor, but you can install the Eclipse XML Editor and Tools from the main software site (category Programming Languages). In order to include the CFS++ schema files go to
Windows => Preferences => XML => XML Catalog
and add a new entry to user specified entries. Insert the location of the schema file which can be found in cfs/share/xml/CFS-Simulation/CFS.xsd.
Further Data: Key: http://www.cfs++.org or http://www.cfs++.org/simulation (after reworked XML schema!130)
You need to repeat to set the spaces for tab convention in
Windows => Prereferences => XML => XML Files => Editor
-> Indent using spaces
-> Indentation size 2
Note that you can auto format by selecting all, right click -> Source -> Format (Sift+Ctrl+F)
Installation URL -> https://raw.githubusercontent.com/15knots/cmakeed/master/cmakeed-update/
PyDev is pretty cool! -> http://pydev.org/updates
TeXlipse is a very nice Latex IDE -> http://download.eclipse.org/texlipse/2.0.2/
Before the debugger can be used properly it has to be set up correctly. At first we have to set the correct path to the application and select the project we want to debug:
- Open Run=>Debug Configurations=>C/C++ Application
- Select your project name and select the Main tab
- Set the correct path for C/C++ Application:
<Build>/bin/cfsbin - Go to Arguments and enter the directory of the file you want to debug under Working directory
- Under Program arguments write the command you would normally use to start the simulation in the terminal, e.g.
-f cantilever(the tag -f forces a SegFault at exceptions) - Go to Debugger tab and untick "Stop on startup at : main".
Afterwards the debugging can be started by either clicking the little bug icon or selecting Run=>Debug. By clicking Run you will be asked if you want to switch to the debug view. Click Yes to get a better overview over variables and the current status of the program. You can switch between the views by clicking on the icons on the top right side (C/C++ to get to the standard view / Debug to get the debug-view).
The navigate in the debugger, you can use the hotkeys F5 to F8:
- F5 step into
- F6 step
- F7 step out
- F8 continue
To be able to debug properly Eclipse has the option to enable breakpoints. They can be enabled by double-clicking on the number of the current line on the left hand side (a little blue dot appears). This tells Eclipse to stop at this point and wait for user input:
The last important part are the additional windows in the debug-view.
- On the top left side you can see the current status of the debugging-process. While being idle (e.g. at a breakpoint) you can see in which file you are as well as the call hierarchy.
- On the top right side you can see multiple tabs of which one is called Variables in this window you can see all current variables and its values which are used inside the current function.
| Shortcut | Action | Where available |
|---|---|---|
| Ctrl+B | Build project (active configuration) | Everywhere |
| Ctrl+H | Search in files, C++ search | Everywhere |
| Ctrl+Shift+R | Open source file from project | Everywhere |
| Ctrl+O | Go to function ("Outline") | C++ editor |
| Ctrl+Space | Auto-complete variable or function name | C++ editor |
| Ctrl+Tab | Toggle header/source file | C++ editor |
| F3 | Go to definition of identifier under cursor | C++ editor |
| Ctrl+3 "keys" | Edit shortcuts. Important, as some don't work on Linux | Everywhere |
Most prepacked versions of eclipse have support for git. You can check easily, if eclipse shows the name of your branch next to the name of the project in the project explorer or if you see the typical git commands in the Team-submenu, when rightclicking a git project/folder/file.
In the rightclick menus Team, Compare With and Replace With, you can find all default git commands like pull, diff, add, commit, checkout (Switch To), rebase etc.
Especially helpful is Team => Mergetool, when you rebase and run into merge conflicts.
You can ignore white spaces when diff'ing or merging by Window => Preferences => General => Compare/Patch => Ignore white space = on
Option: Window => Preferences => General => Workspace => Save automatically before build = on
This occurs when Eclipse crashes without removing its lock on the workspace. You have to delete the lock file manually:
rm /path/to/your/workspace/.metadata/.lockIf Eclipse has problems indexing standard C++ headers such as #include <string>, this is usually caused by an upgrade of GCC (by e.g. upgrading your Linux, or copying the Eclipse installation to a different machine). You have to reset Eclipse's compiler defaults:
- Select Window => Preferences from the menu.
- In the left pane of the Preferences window, navigate to C/C++ => Build => Settings.
- In the right pane select the Discovery tab.
- Select the CDT GCC Built-in Compiler Settings entry and click the Reset button. Now Eclipse should use the defaults of the current GCC version for its Indexer. If you are unsure, if this is actually the case, do the following:
- Select Project => Properties from the menu.
- In the left pane of the Project Properties window, navigate to C/C++ General => Preprocessor Includes.
- In the right pane, on the Entries tab, select GNU C++ under Languages.
- Under Setting Entries click the arrow symbol in front of the CDT GCC Built-in Compiler Settings entry.
- Now you should see the default include directories of your compiler. These are usually directories under
/usr/include/c++. If there are directories marked by an exclamation mark (!), that means these directories do not exist, probably because the GCC version has changed. You can display the default include directories of your compiler by running the following command in a shell (mind the correct type of apostophes!)
`gcc -print-prog-name=cc1plus` -v
The option Window => Preferences => General => Show Heap Status = on displays the current and maximum amount of used memory in Eclipse's status bar (lower right corner of Eclipse window).
Fix works for Luna: In Run => Debug Configurations..., choose Main-Tab and click Select other next to Using GDB(DSF) Create Process Launcher and change setting to Legacy Create Process Lauchner