Archive for December, 2007|Monthly archive page

i386-aros-gcc Compile Options

I tried to research the compile options for the command in my last post. I did not have much luck finding information on it. So I asked thy master, Rob Norris. He explained it extremely well. I wanted to post it here in-case others needed help and to keep a record of it.

I’ll try and explain here. “man gcc” and “man ld” of course have all the info, but are pretty heavy going.

A breakdown:

– i386-aros-gcc: this is running the compiler proper. You need to use a special compiler that knows the specifics of AROS; how its headers and shared libraries work, what features it supports, etc. This is why using the regular “gcc” supplied with your system won’t work for AROS programs.

This is also known as a “cross compiler”, since you’re compiling programs destined for one system (AROS) on a system of a different type (Linux).

– -o hello: specifies the output file, you probably got that.

– -D __AROS__: this predefines a macro and is exactly equivalent to writing ‘#define __AROS__’ someone in the C source file. This is an OS-identifying macro that the SDK cross compiler should be providing itself, which is what mazze and I have been talking about on the aros-dev. There’s a bug in the SDK compiler if it doesn’t provide this, you shouldn’t have had to.

I’ll try to find time over the next week to see about a fix, but frankly the SDK has a lot more wrong with it than just this, which is why I’m making a new development kit.

– hello.c: obviously, specifies the source file.

– -lmui. tells the compiler it should look for any missing functions in a library file called libmui.a. Read on…

Compilation happens in two stages. The compiler takes your C source files, and generates what are known as object files from them. Then a second process known as the linker runs and pulls all the object files and all the libraries you specify using -l together into one file.

As it does this, it resolves references between them. For example, hello.c (via some header file magic you don’t see) tries to call functions called MUI_MakeObject() and MUI_NewObject(). These functions
don’t exist inside hello.c, so when the compiler generates the object file for hello.c (usually hello.o), it will contain information that says “this program will need these functions that I don’t know about”.

This object file is not a program, and cannot be run. If you try to make it into a program without linking it with something that does provide those functions, it won’t know what to do and will tell you about it, eg:

$ i386-aros-gcc -D__AROS__ -o hello hello.c
There are undefined symbols in ‘hello’:
U MUI_MakeObject
U MUI_NewObject

Specifying -lmui is exactly the same as specifying the full path to libmui.a when linking, eg:

$ i386-aros-gcc -D__AROS__ -o hello hello.c /usr/local/i386-pc-aros/lib/libmui.a

Using -l will make the compiler search for it in a number of places.
Your usual compiler will look in /lib, /usr/lib, /usr/local/lib, etc.

The only other thing to understand about this is that the command you’re using will generate the hello.c object file internally, as its trying to produce an executable. You can specify multiple source files, eg:

$ i386-aros-gcc -D__AROS__ -o hello hello.c options.c something.c -lmui

When you do that, it tries to compile all three source files every time, which is wasteful if your project contains many source files. If you only made a change in one of them, then you only want to compile a single file. A better way is to do it with a sequence of commands:

$ i386-aros-gcc -D__AROS__ -c hello.c
$ i386-aros-gcc -D__AROS__ -c options.c
$ i386-aros-gcc -D__AROS__ -c something.c
$ i386-aros-gcc -o hello hello.o options.o something.o -lmui

This demonstrates the split between the compiler and linker. -c tells gcc to invoke the compiler only and produce an object file. You’ll notice that you get a hello.o on your disk after this command. The last command will invoke the linker only, as there are no C files listed.

Later, if you make a change in hello.c, you only need to recompile that file and relink:

$ i386-aros-gcc -D__AROS__ -c hello.c
$ i386-aros-gcc -o hello hello.o options.o something.o -lmui

So its faster, but more work when you’re typing. However by this time you won’t be typing these commands out every time, you’ll be using the make program and a Makefile to automate this for you.

Zune Hello Working

I was able to finally compile the hello.c program shown on aros.org. There were some compile options that I was not aware of and I can’t really find them in the documentation that is on the site. I asked Matthias “Mazze” Rustler to help me. I first added the -lmui option per Mazze’s suggestion, but it still had a problem. Mazze e-mailed the AROS ML and Rob Norris answered helping us figure out the rest of the command needed for the correct compilation. The command is this:

i386-aros-gcc -o hello -D__AROS__ hello.c -lmui

It compiled and I tested it in my AROS hosted environment and it worked like a charm. Phew, now I can move on and play more with Zune. I plan to play with some of the Zune stuff included in the AROS source that I downloaded too. The hello.c was bugging me though, because I wanted to figure out what was going on and why it wouldn’t compile. I still need to research some of the options to understand them better. More to come.

Zune Baby Steps

I have started looking at some Zune source code. I downloaded the AROS core source code. I’ve glanced at the information available on MUI at http://sasg.com/. I have tried compiling the hello.c Zune program available at AROS.org. But I ran into some trouble there. When compiling with the command: i386-aros-gcc -o hello hello.c
I receive errors in mui.h and math.h. I checked to make sure the path was correct and it was and the libraries are there. I must still be missing something.

In the mean time, I downloaded a development environment for Windows called AmiDevCpp. I downloaded the Monster Pack, version 0.9. Then I downloaded the devpacks for AROS. I installed the devpacks by going to Tools/Package Manager in AmiDevCpp. AmiDevCpp looks like a very nice IDE. On Windows, to test AROS applications, you need WinAROS. To transfer your programs over to WinAROS you need WinAROSStart available at the same place.

I have also started reading a book on C. So I’m studying whatever I can to learn what I need to help with Traveller some day. The hello.c in Zune still baffles me, but I’ll ask around and see if I can find out what is going on.

AROS Coding

I have been involved with the operating system AROS for over 2 years now. Up until now, I haven’t done any coding for the project. I have been writing a news site/blog called The AROS Show. Surprisingly it has become a popular site for AROS fans and I am glad! It receives over 80 visits a day.

So, AROS is written in the C language. I have dabbled in C before and I don’t care for it as much as other languages. I have no experience with memory management either. But, I am starting to dive into it again lately. Why you ask? Because there is a project in the works that has me excited and very interested. The project is a web browser for AROS using the WebKit engine. AROS developer Robert Norris has started the project and is in the process of porting WebKit. WebKit is the engine used in Apple’s Safari web browser. Robert documents his progress extremely well on his blog. He has named the browser Traveller. My interview with Robert about this project is here.

I would like to contribute to the Traveller project in the future. That means I need to learn C and the GUI environment in AROS called Zune. It is nearly a clone (at both API and Look&Feel level) of MUI, a well-known Amiga shareware product by Stefan Stuntz. I started last night by downloading the AROS SDK from AROS.org. Linux or BSD is recommended for AROS coding. I followed the directions in the AROS Application Development Manual to make sure I had everything setup correctly. I wrote a quick Hello World program in C and compiled. I copied it over to AROS where I have it running in a hosted environment in Linux. I went to the AROS shell and ran it. It worked just fine. That is all I had time for last night. My next adventure will be in Zune itself.