double-click on it so it will unpack. Using Finder, move the
nbc-1. 2.1.r3.src folder to your applications/NXC folder. In
Figure 2, you’ll see how I created these two essential folder
Step Four: Set up your Makefile, write your source
code, then build!
If we look in the source folder in the NXC folder, we
find — ta da! — our missing NXCDefs.h file! Now that we
know where everything is, we have to use it. Believe it or
not, that Makefile will make this a lot easier. Let’s go back
and look at Listing 1 again. In this Makefile, I set up three
specific locations: where nbc is, where nxtcom is, and
where to look for the NXCDefs.h file.
NBC = /applications/nxc/nbc-1.2.1.r3.osx/nxt/nbc
NXTCOM = /applications/nxc/nbc-1.2.1.r3.osx/nxt/
INCS = /applications/nxc/nbc-1.2.1.r3.src/NXT
Figure 4. The NXT brick and SONAR sensor.
line, I needed to set up my own system. I then looked back
at http://bricxcc.sourceforge.net/nbc and saw that there
was a source release to go along with the executables.
Hmm ... this sounds promising!
Step Three: Get the NXC/NBC source code too!
Using your favorite browser, download the source code
by clicking on the link NBC/NXC 1.2.1.r3 Source release.
Again, you will get a weird file that looks like nbc-
1. 2.1.r3.src.tgz. Your browser will ask you to save or open
it with an archive utility. I like to save the files and open
them later; your mileage may vary. After the file downloads,
Figure 5. NXT display output.
If you set your folders up like I did, this Makefile should
work just fine. Before you build your own program using
the Makefile, you need to have your NXT brick connected
via the USB cable and turned on. If you aren’t, you’ll get:
Error: could not open USB connection NXT. If you have
any program running on the NXT, you’ll get: Error: NXT
Error #8f. (You have been warned!)
To build your NXC program, all you need to do is be in
your source code directory in Terminal. To get there from
anywhere, type: cd ~/Documents/NXC/projects/first.
(This is assuming you’ve created your source code folders as
detailed above.) If you decide to use a different location,
adjust that line accordingly. From your source code
directory, type: make. That’s it. You will see lots and lots of
compiler output spew across your screen telling you
everything that the compiler is doing.
The very last thing the Makefile does is download your
code to the NXT brick. Figure 3 shows the final outcome
of the make command in the terminal window.
No project is complete without pictures, so Figure
4 shows how I set up the NXT and SONAR sensor, and
Figure 5 shows what you should see on the NXT
display when the program is running. I’m assuming
that you have already used your NXT robot brick and
know how to run a program. Using NXC to create and
nxtcom to download the program puts the program on
the NXT brick in the same way that the Mindstorms
graphical programming language does. What you will
notice is that NXC programs are much smaller than the
Mindstorms programs. This is one of the advantages of
To customize this Makefile for any program, all you
need to change is the project name which is set here:
Project name and flags (if any)
PROJ = first
18 SERVO 09.2010