Compiling applications

C and C++ programs can be compiled easily to run on the Microblaze Linux platform. The binaries are dynamically linked against libraries, which are part of the mini-distro. This includes the well-known basic libraries such as glibc and libm, as well as libcrypt, libpthread, libresolv and several others (just list the files in the distro’s /lib for all of them).

To get started immediately, just download the application cross-compilation tarball (~94 MB). Open it anywhere on a Linux computer’s file hierarchy (no superuser access is necessary) and you’re ready to go right away. There is no “installation” necessary.

This package runs on 32-bit Linux as well as 64-bit. A suitable cross compiler for Windows is currently not available.

The cross compilation package has four subdirectories: gnutools, example1, example2 and demoapps. The gnutools subdirectory contains the GNU cross compiler, libraries and utilities. There is no need to look under the hood here.

The two example subdirectories each consist of a Makefile and a sample file to compile. Just change directory to either of them, and type “make” at shell prompt to compile an executable which runs on the platform under Linux.

The "demoapps" subdirectory contains four small programs which demonstrate the coding style for using the Xillybus FPGA IP core, as detailed in a separate page. "make" at shell prompt crosscompiles these programs as well.

These are templates for compiling real applications. We’ll look at the Makefile in the example1 subdirectory:

GNUPREFIX=../gnutools/microblazeel-unknown-linux-gnu/bin/microblazeel-unknown-linux-gnu-

CC=$(GNUPREFIX)gcc
AR=$(GNUPREFIX)ar
AS=$(GNUPREFIX)as
CXX=$(GNUPREFIX)g++
LD=$(GNUPREFIX)ld
STRIP=$(GNUPREFIX)strip

CFLAGS=-Wall -I. -O3

APPLICATION=hello

OBJECTS=#somefile.o somefile2.o etc

all: $(APPLICATION)

$(APPLICATION): $(OBJECTS) $(APPLICATION).o
	$(CC) $(CFLAGS) $(OBJECTS) $(APPLICATION).o -o $(APPLICATION)

clean:
	rm -f *~ $(APPLICATION) *.o

The first line sets the internal variable GNUPREFIX. It’s given as a relative path to the gnutools directory. This is done to make the bundle run out of the box, but it’s also possible to decide on a certain absolute path for the gnutools, and then set GNUPREFIX accordingly.

The CC, AR, AS, CXX, LD and STRIP variables are set so that GNU Make calls the cross compiler rather than the native compiler.

CFLAGS are the flags given to gcc on compilation. In particular, library dependencies go here. For example and as shown in the example2 subdirectory, if mathematical functions such as sin() are used, the “-lm” flag should be added here.

APPLICATION is the name of the final executable. It’s set here to “hello” so a C source file hello.c is expected to have the main() function.

OBJECTS is a space-delimited list of object targets: If the applications is divided into several source files, each should be listed here with the “.c” suffix replaced by “.o”.

The rest of the Makefile sets the targets, so that “make” and “make clean” work properly.

So all in all, this Makefile can be used to compile anything from a simple single-file program to a rather complex software application targeted for the platform.

Next recommended reading: Trying out the Xillybus interface