Saturday, a few of us were trying to get OF working with Eclipse. I had it working sorta cheaply–it required popping out to the shell to run the application once it compiled. Since then, I’ve done some more work and have a better solution.
Eclipse/CDT has it’s own way of setting up C++ projects, but it also allows you to import existing Makefile projects. This is essentially what I did. I started with the Makefile version of OF 0.04 and hooked it up to Eclipse.
Now I am able to compile, run, and debug from Eclipse, not to mention leverage the nice code-completion and syntax highlighting features. I am running Ubuntu Gutsy, Eclipse 3.3, and GCC. Here are the steps:
Install CDT via Europa Discovery Site in Eclipse
Make sure you have gcc installed
Download the Makefile version of OpenFrameworks and get it running from the command line.
In Eclipse, create a new workspace for your OpenFrameworks stuff
Add OpenFrameworks as a generic project in the workspace.
[li]There are a couple of ways to do this. The easiest way is to create an empty project and then copy the files from openframeworks into it.
- Create a new example project
[li]Create an empty C++ Makefile project w/ the same name as the example you want to use
[li]This type of project will automatically use your build file to build the application
- Copy the contents of the of an example app into that project, ie
cp -r ofWorkspace/of/apps/graphicsExample/* ofWorkspace/graphicsExample
Right click, refresh the example project to see the new files in your project explorer
Modify the Makefile so that the paths point to the correct place in the Eclipse workspace
[li]I created a constant in the makefile and included it everywhere in the path, for example:
[li]Near the top:
MYOF = /of
- Then later:
LDFLAGS = -L$(PWD)/..$(MYOF)/libs/fmodex/lib
(replacing …/…/ with …$(MYOF)/ everywhere in the file)
Build the project - if you set up your Makefile correctly, it should build fine, putting the executable in the project’s bin directory, etc.
Next, set up the example project to run from Eclipse
[li]In the project properties window, select “Run/Debug Settings” then “New…” then “C/C++ Local Application” then “OK”
In the “Edit launch configuration properties” dialog, give the configuration a name
In the “Main” tab, C/C++ Application field, enter relative path to the binary, i.e.: bin/graphicsExample
Under the Environment tab, create a new variable called LD_LIBRARY_PATH and set the value to bin/libs/
[li]This does the same thing as the clickToLaunchApp.sh script which is created by make.
Click OK to save this launch configuration and close the properties window
Click the green play button to run the example. It should work
- update your makefile w/ the -g flag for the files you want to debug
$(CPP) -g -c src/testApp.cpp -o obj/testApp.o $(CXXFLAGS)
- make clean to remove previous compiled binaries
[li]in eclipse, this is under ‘Project’ -> ‘Clean’
- click the little bug button and select the run configuration for the current project
[li]This should switch you to the debug perspective and bring you to any breakpoints you set in Eclipse.
Data files, etc
You either need to copy the data directory from bin into the project root directory or symlink it to get examples like moviePlayerExample to work.
I hope this helps anyone who prefers to use Eclipse on Linux as their IDE. I’m sure if I spent some more time, I could make OF work like a regular Eclipse/CDT project instead of a Makefile project, but this really satisfies all my needs. If this is confusing, let me know. Once I make sure I know what I’m doing and have this working for a while, I may be able to make a better tutorial (with graphics and real HTML!).