The Eclipse IDE provides a great toolset for Marlin development work, but out of the box it needs a little tweaking to get it running right. I still use the make files to do the actual production builds of the code, but Eclipse’s built-in compilation and code analysis capabilities are a great asset in understanding and navigating the source files. In particular, I like the fact that Eclipse parses the header files, and simulates the actions of the various pre-processor macros and #defines – greying out any code that won’t be compiled, given your settings in configuration.h, for instance.
I recommend using the Eclipse IDE for C/C++ development, which is available here. For the purposes of this write-up, I just downloaded the 4.3 Kepler version…
Assuming you’ve already gotten the code compiling correctly under Marlin, as discussed above, then once you fire up Eclipse and designate a workspace folder to store your settings in, you can import the existing code as a Makefile project, using the ‘File -> New’ Menu:
This will let you select the outer Marlin folder that you already have set up as location of the code, and designate it for C and C++ code:
Once the file is imported, there are just a few things you need to do, to help Eclipse find its way around the files so that it can analyze and build it properly. Firstly, Eclipse needs to know the path to the inner Marlin directory, where it can find the Makefile. To do this, right click on the Project in the Project Explorer, and select ‘Properties’. Then drill down to the ‘C/C++ Build’ settings, and point the Build location at the inner Marlin directory:
Setting this up will allow you to use the build and ‘make clean’ functionality in Eclipse (running ‘Project -> Clean…’ is a good way to refresh the workspace view, and clean out any old error messages that might be lingering in the Eclipse Problem view).
Next, you need to give Eclipse some pointers to the structure of the project, so it can find the necessary headers during it’s internal build processes. These are added in the ‘Paths and Symbols’ tab of the ‘C/C++ General’ preferences. There are four folders of header files that Eclipse needs to know about:
These settings need to be set up for C and C++ languages, and point at the avr/avr/include, arduino/cores/arduino, libraries/SPI and libraries/LiquidCrystal folders that are part of the Arduino toolset. The paths above, are for the standard Mac OS install of the Arduino tools, but you will need to adjust them for other platforms.
Finally, you need to also define the appropriate architecture type for your printer hardware. This is normally done in the set up for the arduino tools, and so is taken care of when building using make, but Eclipse doesn’t know about it, and so needs to be told, so that all the appropriate pin definitions etc are in place. For the current Ultimaker electronics, the appropriate value that needs defining is __AVR_ATmega2560__.
As a starting point, this XML Eclipse_Imports_and_Symbols definition file can be imported directly into Eclipse from that Paths and Symbols page:
Once these are set up, Eclipse should be able to understand and analyze the Marlin code, without complaining about code problems that don’t show up when actually building the code with make.
You can still build from the command line using make, as discussed in my earlier post, or you can now also use the ‘Project -> Build All’ command in Eclipse.