JetsonHacks

Developing on NVIDIA® Jetson™ for AI on the Edge

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 https://github.com/realdealneil/consoleLinux.git

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
INCLUDE = -I.
LIBS =

OBJS = testconsole.o

${OUTPUTNAME}: ${OBJS}
${CC} -o ${OUTPUTNAME} ${OBJS} ${LIBS}

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

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

clean:
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.

 

Facebook
Twitter
LinkedIn
Reddit
Email
Print

6 Responses

  1. I would be very interested in developing for CUDA in code::blocks. I’m not entirely new to linux, but I am new to developing on an embedded platform and for CUDA. I’ve been running into hiccups that wouldn’t be issues for me on a x86 build.

    Do you also have any suggestions for Python IDEs on the TK1?

    1. I’ll try to cover CUDA soon, and how to use it within code::blocks. It’s not too bad, but there are some gotchas (and I’m sure I haven’t discovered them all yet). For python, I like spyder…since you asked, I went ahead and installed in on my Jetson, and it looks like it at least works. You can just run ‘sudo apt-get install spyder’ and it will install all the dependencies (like scipy and matplotlib). It’s a pretty nice IDE that resembles Matlab. It did install a lot of packages, so be careful if you’re low on disk space.

  2. I’d like to see the CUDA stuff too. I’d really like to turn the TX1 dev kit into a mobile CUDA computer dev system. I know a laptop would be better suited, but I already have the TX1. I’m not sure why Nsight and the rest of the tools don’t work directly on the TX1 since that seems ideal. Kinda a bummer.

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclaimer

Some links here are affiliate links. If you purchase through these links I will receive a small commission at no additional cost to you. As an Amazon Associate, I earn from qualifying purchases.

Books, Ideas & Other Curiosities