If you are a Java developer used to the productivity levels achieved by working with eclipse’s code navigation, code completion and refactoring tools, it’s worth your time staying in eclipse for any sort of C++ development.
This post refers specifically to getting your eclipse environment to work with a particular C++ Open Source project, The Bitcoin Project.
Before you start setting up eclipse, please make sure you can build Bitcoin from the command line, this way you know that you have everything necessary to build Bitcoin, even if you’re still getting a few errors showing in Eclipse, in the end Eclipse will be using the Makefiles provided by the project whenever we need to compile (and it can do so incrementally when possible saving you a lot of compilation time)
I’m assuming you have installed:
- eclipse CDT tools, up to date for the version of eclipse you’re working with (I’m still working with Juno)
- Qt/Eclipse plugin (optionally)
- All the dependencies (autoconf automake berkeley-db4 boost miniupnpc openssl pkg-config protobuf qt gdb) necessary to build Bitcoin which are easily installable via HomeBrew.
1. Let’s import the bitcoin/ project to our workspace.
File > Import > Existing Code as Makefile Project
Look for the bitcoin/ git checkout folder, and make sure you use the GNU Autotools Toolchain
2. Fixing the C++ compiler Path and Symbols.
Right click on the project containing folder in the Project Explorer > Properties.
Go to C/C++ General > Paths and Symbols > Languages: GNU C++ > “Includes” Tab and make sure it looks something like the screenshot below (I got those paths by looking at the ones used by the Makefiles in the Bitcoin. Hit Apply , OK, then wait for the reindexing, you might still have a few weird errors because of how the compiler checking settings are.
3. Remove a few more issues like “
Error: Invalid arguments candidates are: void resize(?, int)."
We open again the project Properties, this time we go to C/C++ General > Preproessor Include Paths, Macros, etc.
Click on the Providers tab and make sure “CDT GCC Built-in Compiler Settings [Shared]” is checked. Hit Apply, OK, wait for reindexing.
If there are still errors, you might want to just delete them and refresh the project (F5 on the project folder in the Project explorer), all errors should be gone by now.
Now start working just as fast as you’re used to with Java on Eclipse.
Project wide renaming refactors in seconds…
Find references of variables, methods, classes (Cmd+Shift+G)
Find all the implementations of an interface (Cmd+T)
and best of all
Interactive debugging with gdb*
and all the tools you know and love from Eclipse.
*Setting up GDB debugging
To do step by step debugging you can use gdb, if you don’t have it installed just go to your Terminal and type brew install gdb.
On your command line, execute your Makefile to create an executable, once it appears on your Project Explorer you can Right click on it Debug As > Debug Configuration…
then make sure you have set gdb as the executable debugger in the “Debugger” configuration tab, then just set your breakpoints and debug away!
Not so fast…
As of Mac OSX 10.9, Apple decided that you cannot use gdb unless the gdb executable is signed with a certificate, they want you to use their super duper lldb debugger, but it’s still not compatible with Eclipse, you know, so you use their XCode IDE instead of what you want to use…
Anyways, signing the gdb at /usr/local/bin/gdb is not that hard.
To sign it you can create a certificate, or use an existing developer certificate. In my case, I already had a Mac Developer certificate so it was a very simple process, just issuing a single command in the Terminal and I finally got rid of the
"Unable to find Mach task port for process-id 93213: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))" error.
codesign -s “Name of my certificate here” /usr/local/bin/gdb
Then I tried debugging, I got a password dialog to verify I was the owner of the certificate, and then gdb could take over and then I could do my step by step debugging, with the ocassional crash.