Site icon JetsonHacks

Using Code::Blocks on Jetson

codeblocks2Jetsonhacks himself has been kind enough to let a fellow jetsonhacker have a hand at adding some blog posts…so here goes.  I’ll just do a real quick intro of myself: My name is Neil, and I like the Jetson.  Good enough?  Okay, let’s move on to the topic at hand: Using Code::Blocks on the Jetson.

So, if you’ve never heard of code::blocks, it is an open source IDE.  It’s not the best IDE in the world, but it’s not the worst either.  I’d put it pretty close to the middle of the pack as far as functionality…but what it lacks in features, it makes up for in price: $FREE.  That’s a hard price to beat.

The reason I wanted to do a post about Code::Blocks on the Jetson is that for a while, I was coding on the Jetson without an IDE, and that got old.  I wanted the ability to step through code and group files together in projects.  Though Makefiles can do part of this, and gdb has some GUI front-ends (like DDD which is horrendous), I decided to try code::blocks owing to its freeness.

So, this post is about using Code::Blocks to replace an existing Makefile project and to provide the basic abilities of putting breakpoints in your code and debugging on the Jetson.  We won’t do any cross-compiling…everything will be done on the Jetson itself (easier that way, ain’t it?).

First, let’s install Code::Blocks:

sudo apt-get install codeblocks

I installed this a while ago, so hopefully I’m not forgetting any dependencies (if I did, let me know in the comments and I’ll add them). You should also be able to install it through Ubuntu Software Center.

Okay, now it’s installed. Let’s take a look at a simple C++ project that currently uses a Makefile and convert it into a Code::Blocks project (.cbp file).  I have an example that I’ll use on github that uses ANSI codes to print stuff to a terminal and periodically clear the screen so that the screen updates in a nice fashion.  You can clone it from here:

git clone

If you go into the folder you just cloned, you’ll see a Makefile that looks like the following:

# Console Test makefile

CC = g++
OUTPUTNAME = testconsole

OBJS = testconsole.o


%.o: %.cpp
${CC} ${CFLAGS} ${INCLUDE} -c $*.cpp

rm -f ${OBJS} @echo “all cleaned up!”

rm -f ${OUTDIR}/${OUTPUTNAME} ${OBJS} @echo “all cleaned up!”

So, a nice simple makefile.  You can run ‘make’ at the command prompt and it will create a program call testConsole that you can run and see the output.  Now, let’s take this project and make it compile in Code::blocks.  (I’ve actually already made a codeblocks project and checked it in to git, which you can use if you don’t want to learn anything here…if you do, then keep reading and make your own with a different name).

Open codeblocks (you should be able to hit the ‘windows’ key and type codeblocks…add it to your shortcuts if you like).  Click on the New icon, and select Project…   In the dialog, select the option to make an empty project, give it a name, and put it in the folder where you cloned the project earlier.  (I got rid of the intermediate directory it tried to make so that the project file will be in the same folder as the Makefile).  Hit ok, and choose “GNU GCC Conpiler” as the compiler for release and debug modes.  Click “Finish”.

Now, we need to add files to our project.  Right-click on the project name in the Projects/Workspace area and select “Add Files…”.  Add testconsole.cpp and consoleLinux.h.
Let it add these to both debug and release profiles.  On the top toolbar, click the gear icon to build.  Then, you can run by hitting the green triangle.

If you want to debug, build using the Debug profile, and use the red triangle to do a debug run (I don’t like that they have two separate run methods…but, I guess that’s how it is).  You can add breakpoints to the files if you want to step through the code.

Well, that’s about it.  I will try to do some videos in the future to make this more engaging.  I intend to do another post soon that describes how to configure a project in Code::Blocks to allow for CUDA programming using the NVCC compiler.  If you’re interested, leave a comment.


Exit mobile version
Skip to toolbar