GP32 Some Help Understanding Makefiles?


Melville

Member
Joined
Apr 24, 2003
Messages
102
Hi,
I'm having difficulty compiling "hello.c", the hello world program for MeMirko's SDK described in the tutorials section on this site. I know that Hello World should be completely idiot-proof, but I'm no ordinary idiot! :)

What I've done so far:
*****************************************************************
Downloaded (from http://www.mirkoroller.de/gp32):
"Arm9 gcc crosscompiler for windows[95-XP] with gp32 tools"
"SDK082.bz2"
Extracted the cross-compiler to c:\gp32_MrMirko\
Into which I put the SDK082.bz2 and ran "extractsdk", which unzipped a load of stuff into c:\gp32_MrMirko\gp32_sdk\
Included with the cross-compiler was a batch file called "compile". If I copy this into one of the example folders in the gp32SDK folder and click it, it compiles without any difficulty. So the compiler seems to be installed ok.
****************************************************************

Now the problem: I can't compile "hello.c". I'm guessing that it needs a makefile, but I really have no idea how to write one. I have tried using modified versions of makefiles found in the examples: changed the filename, left everything else alone. This gave me an error telling me it can't find the obj files. I deleted all references to obj files in the makefile (as AFAIK hello.c doesn't have any), and I now get the error:

C:\gp32_MrMirko\gp32_SDK\Projects>compile
make: *** No rule to make target `arm-elf-gcc', needed by `all'. Stop.

Any ideas why it isn't working?

Also, just typing gcc hello.c gives me:

C:\gp32_MrMirko\Projects>gcc hello.c
gcc: installation problem, cannot exec `cc1': No such file or directory

Is there any chance someone could post a sample makefile (ideally with explaination) which should work? A link to a decent guide about makefiles would also be very useful. Googling just gives me links to guides for unix, which I'm told works differently, or very specific examples which I don't know enough to understand.

Argh, this post has turned epic, but I thought lots of info would help get the right solution... maybe it'll just scare people off instead!

Thanks in advance (and for just reading this far!)
Melville - who will get his game written if it kills him!
 
Hi,
I'm having difficulty compiling "hello.c", the hello world program for MeMirko's SDK described in the tutorials section on this site. I know that Hello World should be completely idiot-proof, but I'm no ordinary idiot! :)

What I've done so far:
*****************************************************************
Downloaded (from http://www.mirkoroller.de/gp32):
"Arm9 gcc crosscompiler for windows[95-XP] with gp32 tools"
"SDK082.bz2"
Extracted the cross-compiler to c:\gp32_MrMirko\
Into which I put the SDK082.bz2 and ran "extractsdk", which unzipped a load of stuff into c:\gp32_MrMirko\gp32_sdk\
Included with the cross-compiler was a batch file called "compile". If I copy this into one of the example folders in the gp32SDK folder and click it, it compiles without any difficulty. So the compiler seems to be installed ok.
****************************************************************

Now the problem: I can't compile "hello.c". I'm guessing that it needs a makefile, but I really have no idea how to write one. I have tried using modified versions of makefiles found in the examples: changed the filename, left everything else alone. This gave me an error telling me it can't find the obj files. I deleted all references to obj files in the makefile (as AFAIK hello.c doesn't have any), and I now get the error:

C:\gp32_MrMirko\gp32_SDK\Projects>compile
make: *** No rule to make target `arm-elf-gcc', needed by `all'. Stop.

Any ideas why it isn't working?

Also, just typing gcc hello.c gives me:

C:\gp32_MrMirko\Projects>gcc hello.c
gcc: installation problem, cannot exec `cc1': No such file or directory

Is there any chance someone could post a sample makefile (ideally with explaination) which should work? A link to a decent guide about makefiles would also be very useful. Googling just gives me links to guides for unix, which I'm told works differently, or very specific examples which I don't know enough to understand.

Argh, this post has turned epic, but I thought lots of info would help get the right solution... maybe it'll just scare people off instead!

Thanks in advance (and for just reading this far!)
Melville - who will get his game written if it kills him!
Are you sure you set the path corecctly in windows enviroment.
( read readme how to do this ) ( from cross compiler)


You can check the cross copiler working, just enter one example folder
and type:

make

a fxe file should be created.

Later if this is working, you can copy compile.bat to an example folder, and double
click it. So you dont need to enter the cmd shell every time.
 
Last edited by a moderator:
Going to a directory contiaining no makefiles etc, typing "make" throws up the following error:

C:\temp>make
make: *** No targets specified and no makefile found. Stop.

No .fxe file is added to the directory

The text I added to the end of my path is ";c:\gp32_MrMirko\bin" (without quote marks)

c:\gp32_MrMirko\bin contains 40 files (mostly *.bat files) including make.bat and gcc.bat

Odd. maybe I'm just cursed :blink:
 
Going to a directory contiaining no makefiles etc, typing "make" throws up the following error:

C:\temp>make
make: *** No targets specified and no makefile found. Stop.

No .fxe file is added to the directory

The text I added to the end of my path is ";c:\gp32_MrMirko\bin" (without quote marks)

c:\gp32_MrMirko\bin contains 40 files (mostly *.bat files) including make.bat and gcc.bat

Odd. maybe I'm just cursed :blink:
C:\temp>make
make: *** No targets specified and no makefile found. Stop.

go to the directory

c:/gp32_MrMirko/gp32_sdk/example.font
and type:

make

NOW make is calling the Makefile in this directory,
and starts builing the fxe file.
 
Last edited by a moderator:
Yes, that worked.

Sorry, that should've been obvious :unsure:. I had been revising for a statistics exam all day, so my brain wasn't working properly!

So is it safe to assume that the problem is with the makefile I'm trying to use rather than a bad install? When my exams are over (wednesday - woohoo!) I'll have a hunt around for guides on writing makefiles.

Thanks very much for your help. I've been searching through the furums quite a lot recently, and I'm amazed that you're writing such a great SDK in your spare time and still manage to post the amount of help to individual people that you do.

Melville
 
So is it safe to assume that the problem is with the makefile I'm trying to use rather than a bad install? When my exams are over (wednesday - woohoo!) I'll have a hunt around for guides on writing makefiles.
Try http://www.eng.hawaii.edu/Tutor/Make/, it's not too bloated. Just about 20 not too long pages explain the idea of makefiles and splitting your code in several files. You'll should get to it in 30-60 minutes.

Greetings,
SvOlli
 
Last edited by a moderator:
The Saga continues...

Thanks to the guide suggested by SvOlli I think I now understand most of the makefile. I'm definately making progress, but not quite there - still get an error while compiling. Here's my makefile (based on the sample makefile from the SDK) and what I think it does:

Code:
CC = arm-elf-gcc
LD = arm-elf-gcc
AS = arm-elf-as
AR = arm-elf-ar
PRG = hello
Defines CC, LD, AS, AR and PRG as synonyms for the command written after them, so later in the code they can just be typed as $(CC) etc.

Code:
LIBS = ../lib/gp_common.a ../lib/gp_font8.a
INCLUDES = -I../lib.src/include
CFLAGS = $(INCLUDES) -O2 -s  -mtune=arm9tdmi
Tells the compiler (or is it the linker?) where to find libary files containing the custom commands like gpSetScreen, and the include files (contains headers / definitions). It's assumed that the addresses given (e.g. "../lib.src/include") is nested within the current directory. I think...

I have no idea what the -I switch in INCLUDES is, but when I remove it I get a new error message... so I've left it alone!

CFLAGS tells the compiler to look up some previously defined rules for interpreting the code. Presumably this is so it outputs a file suited for GP32 processor rather than windows. As long as I stick with GP32 I won't need to mess with this.

Code:
OBJS =  hello.o
Another synonym used later in the program. I think- as this program is just one hello.c file - the only program name I need to put hello.o here. As I understand it, the assembler creates this file and we need to tell the linker which object files to add together to form the final application.


Code:
all:	$(OBJS)

# Add all of (your-.c-file).o after $(PRG).elf
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map  -T lnkscript crt0.o -o $(PRG).elf $(PRG).o $(LIBS)
	arm-elf-objcopy -O binary $(PRG).elf $(PRG).bin
No idea what most of this does. A list of things to be compiled, perhaps? I don't have any extra object files, so haven't added anything to this.

Code:
b2fxec -a Mirko_Roller -t DoubleBuffered_fx $(PRG).bin $(PRG).fxe
Changes the final file produced to a .fxe file.

If I'm wrong in my interpretation of things in here, please let me know :).

My latest error message is:
C:\gp32_MrMirko\gp32_SDK>make
arm-elf-gcc -I../lib.src/include -O2 -s -mtune=arm9tdmi -c -o hello.o hello.c

hello.c:100:77: gp32.h: No such file or directory
hello.c: In function `main':
hello.c:107: error: `FRAMEBUFFER' undeclared (first use in this function)
hello.c:107: error: (Each undeclared identifier is reported only once
hello.c:107: error: for each function it appears in.)
hello.c:105: warning: return type of `main' is not `int'
make: *** [hello.o] Error 1
The definition of INCLUDES in my makefile is INCLUDES = -I../lib.src/include. The files hello.c, makefile, lnkscript and crt0.S (not sure if I really need the last two there) are all in :
c:\gp32_MrMirko\gp32_sdk\, so the INCLUDES statement should point to:
c:\gp32_MrMirko\gp32_sdk\lib.src\include (I think). This folder DOES contain gp32.h (among other files), so I can't work out why the compiler doesn't see it. It seems to be finding the library file ok (as it doesn't give any errors about unrecognised functions), so I don;t understand why it can't see gp32.h. Does anyone have any theories?

Dear god, I just realised how long this post it. Sorry for takin up so much of your time with my newb questions!
 
I have no idea what the -I switch in INCLUDES is, but when I remove it I get a new error message... so I've left it alone!

The -I switch tells the compiler there to find the include files (*.h)
-Ic:/blubber searches for *.h files in dir c:/blubber

C:\gp32_MrMirko\gp32_SDK>make
arm-elf-gcc -I../lib.src/include -O2 -s -mtune=arm9tdmi -c -o hello.o hello.c

hello.c:100:77: gp32.h: No such file or directory
hello.c: In function `main':

Yes, hello.c can not find gp32.h file, becouse the -I string is wrong.
you can copy gp32.h to you directory, and change -I to -I.

Or set the complete path to the include dir there the gp32.h file is.
-IC:\gp32_MrMirko\gp32_SDK\lib.src\include
 
I know this shouldn't be difficult, but it's driving me insane!

I tried using the code above but putting the full addresses for the includes. The error message changed to one telling me it couldn't find the libs, so I also put the full address for the libs into the code. (By the way, should it be "c:\folder\subfolder" or "c:/folder/subfolder" - neither direction of slashes makes it work, but I'm curious!)

So, a new approach. I tried compiling the file "sprite.c" which is in the folder

c:\gp32_mrmirko\gp32_SDK\example.sprite\

along with crt0.s, lnkscript, a folder called "sprites (containing *.bmp files) and its own makefile. Compiling this works perfectly except for the cleanup - the .fxe is produced, but the .o filea and test.map aren't deleted. I can live with deleting my own files though, so that's not important.

Now, what I did was:
Move everything except the makefile, lnkscript and crt0.s to a different folder.
Put hello.c into the folder
Open the makefile, and change two lines of the file. The first thing I change is
Code:
PRG=sprite
to
Code:
PRG=hello

The second thing is to change

Code:
OBJS =  sprites/garfield.o  sprites/odie.o  sprites/test.o  sprite.o
to
Code:
OBJS =  hello.o

I save and exit the makefile, so the folder now contains:
hello.c
makefile (identical to the working makefile for sprite, just with the name changed and pictures removed)
lnkscript (was in the folder when sprite.c compiled successfully)
crt0.s (was in the folder when sprite.c compiled successfully)

I enter DOS shell, get to that directory (c:\gp32_mrmirko\gp32_sdk\example.sprite) and type "make". This error pops up:

Code:
C:\gp32_MrMirko\gp32_SDK\example.sprite>make
arm-elf-gcc -I../lib.src/include -O2 -s -w -mtune=arm9tdmi   -c -o hello.o hello
.c
arm-elf-gcc -c -o crt0.o crt0.S
arm-elf-gcc -nostartfiles -s -Wall -Wl,-Map,Test.map  -T lnkscript crt0.o -o hel
lo.elf hello.o  -L../lib -lmirkoSDK
hello.o(.text+0x24): In function `main':
: undefined reference to `gp_SetScreen'
hello.o(.text+0x50): In function `main':
: undefined reference to `gp_SetCpuSpeed'
hello.o(.text+0x98): In function `main':
: undefined reference to `gp_SetFont8'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I probably sem very stupid, but I don't understand why just changing the name of the file it referrs to can introduce an error like this. I assume it isn't finding the library file, but don't understand why. I've tried several ways of giving it the full address to the library file, but can't get past this error. Do I need to change the contents of lnkscript or crt0.s in some way?

Here's the makefile:

Code:
CC = arm-elf-gcc
LD = arm-elf-gcc
AS = arm-elf-as
AR = arm-elf-ar

PRG = hello   (<- this was originally "sprite")

LIBS = -L../lib -lmirkoSDK

INCLUDES = -I../lib.src/include

CFLAGS = $(INCLUDES) -O2 -s -w -mtune=arm9tdmi

 
OBJS =  hello.o  (<- this was originally "OBJS =  sprites/garfield.o  sprites/odie.o  sprites/test.o  sprite.o")

all:	$(OBJS)
	$(CC) -c -o crt0.o crt0.S
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map  -T lnkscript crt0.o -o $(PRG).elf $(OBJS) $(LIBS)
	arm-elf-objcopy -O binary $(PRG).elf $(PRG).bin
	b2fxec -a Mirko_Roller -t SDK_EXAMPLE_$(PRG) $(PRG).bin $(PRG).fxe

install:
	gplink put $(PRG).fxe gpmm

clean:
	rm -f *.o *~ Test.map *.bin *.elf

The makefile, hello.c, crt0.s and lnkscript are located in c:\gp32_MrMirko\gp32_SDK\example.sprite
The library is: c:\gp32_MrMirko\gp32_SDK\lib\libmirko.a
The includes are in c:\gp32_MrMirko\gp32_SDK\lib.src\include\ (Contains six *.h files)

Is there any obvious reason why this isn't working? I hate making myself look stupid like this, but I've spent ages moving files around, typing addresses in every permutation I can think of, writing my own makefiles, simplyfieing makefiles from the examples and hitting my computer. Nothing worked, and stopping now would mean admitting defeat!

So don't excuse my stupidity, but please take pity on it! Thanks very much for all your help so far guys, it's been great!
 
Lemme give you some quick shots:

Usually the compiler is taken as a wrapper for the linker, so that might get your compiler/linker confusion a bit clearer.

The "objcopy" command transfers the elf (executable and linkable format, iirc) to a flat binary file. The elf format includes infomation about the architecture (arm, little endian, amongst others), needed shared libraries (not used on gp32), debugging information and a lot of other more or less useful information. The elf file needs an OS to interpret the header and start the file (entrypoint is also defined in elf header). The flat binary will be executed by jumping to the very first byte of file. So if you try to execute an elf like a flat binary, you'll try to execute the header, which just won't work ;) .

If you use an
#include "header.h"
statement in you C/H-file it will look for the header in the directory of that file.
If you use an
#include <header.h>
statement in you C/H-file it will look for the header in the system include directories which can be expanded by using the "-I"-option.

Analog to that works the "-L"-option during linking for libraries included with the "-l"-option. Example:
Code:
$(CC) -o player.fxe player.o -LgpTremorDir -lgpTremor
will look for the library as "gpTremorDir/libgpTremor.a". Note that the library filename must like "lib$(LIBRARY).a". If you specify more than one "-L"-option they all will be searched till a matching library is found.

To get past the error, the most elegant thing to do is to create a directory "work" (or what you'd like to call it) in the gp32_SDK directory and move all your files needed (like *.[ch], Makefile, lnkscript) to that directory and try make from there. Then the approach of specifying paths starting with "../", which tells to go one up, should work.

Greetings,
SvOlli
 
I think I understand you:

c:\gp32_MrMirko\gp32_SDK\Projects
contains hello.c, lnkscript, crt0.s and the makefile

From the makefile:
Code:
LIBS = -L../lib -lmirkoSDK
The ".." makes it go up a directory to c:\gp32_MrMirko\gp32_SDK
then it looks for a directory called lib, and looks inside c:\gp32_MrMirko\gp32_SDK\lib
The "-lmirkoSDK" makes it look for a file called libMirkoSDK.a

The file c:\gp32_MrMirko\gp32_SDK\lib\libmirkoSDK.a does exist - as far as I can tell, the compiler should have no problem finding it

Similarly,
Code:
INCLUDES = -I../lib.src/include
".." = up a directory to c:\gp32_MrMirko\gp32_SDK
"/lib.src/include" Makes it look in c:\gp32_MrMirko\gp32_SDK\lib.src\include, where the GP32.h file is located.

This seems to make sense, and as far as I can see works for all of the example programs. But when I try to compile hello.c using the makefile above (with the LIBS and INCLUDES modified as in this post), I still get the error
Code:
arm-elf-gcc -c -o crt0.o crt0.S
arm-elf-gcc -nostartfiles -s -Wall -Wl,-Map,Test.map  -T lnkscript crt0.o -o hel
lo.elf hello.o -L../lib -lmirkoSDK
hello.o(.text+0x24): In function `main':
: undefined reference to `gp_SetScreen'
hello.o(.text+0x50): In function `main':
: undefined reference to `gp_SetCpuSpeed'
hello.o(.text+0x98): In function `main':
: undefined reference to `gp_SetFont8'
collect2: ld returned 1 exit status
make: *** [all] Error 1


Am I correct in assuming this error is a result of the compiler failing to find / use the library? I have to admit that I'm completely stumped by this. If I understood your post correctly, all of the files necessary are where the makefile says they should be. Argh, by the time I discover why it isn't working Alessandro will have published his IDE!
Maybe I need to hire an excoricist to take a look at my computer...
 
Code:
arm-elf-gcc -c -o crt0.o crt0.S
arm-elf-gcc -nostartfiles -s -Wall -Wl,-Map,Test.map  -T lnkscript crt0.o -o hel
lo.elf hello.o -L../lib -lmirkoSDK
hello.o(.text+0x24): In function `main':
: undefined reference to `gp_SetScreen'
hello.o(.text+0x50): In function `main':
: undefined reference to `gp_SetCpuSpeed'
hello.o(.text+0x98): In function `main':
: undefined reference to `gp_SetFont8'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Am I correct in assuming this error is a result of the compiler failing to find / use the library?
You could do an arm-elf-nm ../lib/libMirkoSDK.a to get a dump of all symbols (functions/global variables) used. Once you've looked there, you'll notice that you've spelled these functions wrong. C variable and function names are case sensitive. B)

Greetings,
SvOlli
 
Last edited by a moderator:
Wow, that's an embaressing mistake!

It seems the tutorials (from the tutorials section on this forum) are out of date - use old versions of commands, no longer supported by the version of the SDK I have (version 0.8.2).

Looking through the documentation, I've replaced the obsolete commands with the new ones, and it compiles fine! I also found the "how to write makefiles" section at the end... even more embaressing!

Thanks very much for all your help, you've been great and very patient with my uber-n00b (l33t-speak makes me giggle :)) questions! Over the next few days I'll check through the MrMirko tutorials on this site and post versions with the new commands where necessary.

Thanks a lot guys :)
Melville
 
Wow, that's an embaressing mistake!

It seems the tutorials (from the tutorials section on this forum) are out of date - use old versions of commands, no longer supported by the version of the SDK I have (version 0.8.2).

Looking through the documentation, I've replaced the obsolete commands with the new ones, and it compiles fine! I also found the "how to write makefiles" section at the end... even more embaressing!

Thanks very much for all your help, you've been great and very patient with my uber-n00b (l33t-speak makes me giggle :)) questions! Over the next few days I'll check through the MrMirko tutorials on this site and post versions with the new commands where necessary.

Thanks a lot guys :)
Melville
> Over the next few days I'll check through the MrMirko tutorials on this site and post versions with the new commands where necessary.

You can use the tutorial files in the SDK help directory, i changed all names, so they now fit the new functions calls.

If someone could check the tutorial files in the help dir ? And change them on this website, couse they use the old function names.
 
Last edited by a moderator:
Back
Top