#39390 - DKX - Fri Apr 08, 2005 8:18 am
I'm one of those spoiled programmers - I've always had Microsoft there to automate the compilation and linking - so compiling for the GBA introduced a host of problems. Fortunately, GBAForVS6 let me get down to coding. However, I seem to have hit something of a snag.
I'm in the process of following the tutorial at http://www.thepernproject.com/tutorials/GBA/day_2.html, and since I've never tried combining ASM with C before, the .s file is entirely new to me. When I compile my source, the linker responds with "undefined reference to `picture'", indicating the last line of my main() function. Do I need to update something to include that file in the compilation, or compile it separately?
Resource.s
Code: |
.global picture
.text
.align 4
picture:
.incbin "images/_RedGreenBox.pcx"
|
main.c
Code: |
#include <stdlib.h>
#include <C:\Program Files\Microsoft Visual Studio\VC98\Include\gba.h>
#include "gbadef.h"
#include "PCX.h"
int main()
{
/**/extern WORD * picture;
/**/#define sImage PCXImage;
int i;
PCXImage image;
if(LoadPCX(picture, &image) != 0)
{ REG_DISPCNT = (MODE_4 | BG2_ENABLE);
for(i = 0; i < ((ScreenWidth * ScreenHeight) >> 1); i++)
{ FrontBuffer[i] = image.data16[1];
}
for(i = 0; i < 256; i++)
{ BGPaletteMem[i] = image.palette[i];
}
while(true)
{ if(KEY_PRESSED(KEY_A))
{ REG_DISPCNT ^= BACKBUFFER;
}
}
}
return 0;
}
|
[Off-topic]
Am I the only one having trouble connecting to http://www.devkit.tk ? I keep getting "Unknown host"
[/Off-topic]
#39391 - DekuTree64 - Fri Apr 08, 2005 8:31 am
Your code looks fine. I'm guessing the assembly file isn't actually building at all, or maybe just not being linked.
Post your makefile and it will probably be pretty easy to add a rule for them.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#39394 - DKX - Fri Apr 08, 2005 8:57 am
Thanks for the reply. As I said, I'm new to the building process, so any help is appreciated.
Makefile.mak
Code: |
# PROJECTNAME is the ROM's filename
# ROMTITLE is the title embedded in the ROM's header
PROJECTNAME = GBA_TEST01
ROMTITLE = $(PROJECTNAME)
# BUILDDIR is the subdirectory where the ROMs will be placed
BUILDDIR = bin
#-- Nothing below here should need to be changed. --
# Paths to tools
DEVKITDIR = C:\Program Files\GBAForVS6\DevKitARM
GBAFORVSDIR = C:\Program Files\GBAForVS6
# Build tools (compiler, linker, etc...)
CC = "$(DEVKITDIR)\bin\arm-elf-g++"
LD = "$(DEVKITDIR)\bin\arm-elf-g++"
AS = "$(DEVKITDIR)\bin\arm-elf-as"
OBJCOPY = "$(DEVKITDIR)\bin\arm-elf-objcopy"
GBAFIX = "$(DEVKITDIR)\bin\gbafix"
PROJOBJ = "$(GBAFORVSDIR)\ProjObjExtractVS6.exe"
# The following generates the macro O_FILES, a listing of the object files.
#
# The !IF/!ENDIF are there just to get NMAKE's preprocessor to run ProjObjExtractVS6,
# which generates a list of object files from your Visual Studo project file.
# The !INCLUDE statement loads the resulting output. See readme.txt for some notes.
#
!IF [$(PROJOBJ) "GBA_TEST01.dsp"]
!ENDIF
!INCLUDE sources.inc
.SUFFIXES :
.SUFFIXES : .elf .o .cpp .c .s
INCDIR = "$(DEVKITDIR)\lib\gcc\arm-elf\3.4.1\include"
INCDIR2 = "$(DEVKITDIR)\arm-elf\include"
CFLAGS = -I $(INCDIR2) -I $(INCDIR) -mtune=arm7tdmi -mcpu=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -c -g -O3 -Wall
SFLAGS = -I $(INCDIR2) -I $(INCDIR) -mthumb-interwork
LDFLAGS = -g -mthumb-interwork -specs=gba.specs
all : $(BUILDDIR)\$(PROJECTNAME).gba
@echo Done Building!
# Create ROM
{.}.elf{$(BUILDDIR)}.gba :
@echo ------------------
@echo Generating ROM...
@echo ------------------
$(OBJCOPY) -v -O binary $(*B).elf $@
@echo -------------------
@echo Patching Header...
@echo -------------------
$(GBAFIX) $@ -t$(ROMTITLE)
# Link
$(PROJECTNAME).elf : $(O_FILES)
@echo -----------
@echo Linking...
@echo -----------
$(LD) $(LDFLAGS) -o $@ $(O_FILES)
# Compile
.c.o ::
@echo -----------------------
@echo Compiling C Sources...
@echo -----------------------
$(CC) $(CFLAGS) $<
.cpp.o ::
@echo -------------------------
@echo Compiling C++ Sources...
@echo -------------------------
$(CC) $(CFLAGS) $<
.s.o ::
@echo -------------------------
@echo Compiling Asm Sources...
@echo -------------------------
$(AS) $(SFLAGS) $<
clean :
@echo ------------
@echo Cleaning...
@echo ------------
del $(O_FILES)
del $(PROJECTNAME).elf
@echo Done!
|
#39395 - DekuTree64 - Fri Apr 08, 2005 9:27 am
Hmm, I don't see anything suspicious right off the bat, but this block is mainly what I was looking for:
Code: |
!IF [$(PROJOBJ) "GBA_TEST01.dsp"]
!ENDIF
!INCLUDE sources.inc |
Up above, it says that defines O_FILES, which is your list of .o files to link into the .elf. It's possible that the .s file isn't getting included there, although it looks to me like it would be, provided that you have the .s file in your .dsp. You could try taking a look at sources.inc to see if all the .c files are there and the .s is not.
If that's not the problem, try putting extern "C"{} around your extern declaration, like
Code: |
extern "C"
{
extern WORD * picture;
} |
Since you're using G++ to compile, it may actually be building your .c file as C++. I think C++ only mangles function names, but it may do it to data pointers as well, so it's worth a try.
Or just switch your CC/LD definitions to arm-elf-gcc instead of arm-elf-g++.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#39464 - DKX - Sat Apr 09, 2005 6:15 am
Sorry for the delay (life called...). Indeed, sources.inc contains two lines:
O_FILES = \
".\main.o"
So how do I add it? A bit of MSDN-style research into make files hasn't revealed anything beyond what you've said, and nothing I try seems to get the job done.
#39465 - DekuTree64 - Sat Apr 09, 2005 6:40 am
I've never used that ProjObjExtractVS6 tool, so I don't know if it only grabs .c/.cpp files or what. Make sure you have the .s in your VC++ project, in the source files workspace folder thing wherever main.c is (if it's not there, right click and hit 'Add Files to Folder...' and add it).
If all else fails, just rip out that whole !IF/!ENDIF/!INCLUDE and replace it with something like
Code: |
O_FILES =\
".\main.o" \
".\picture.s" |
Like how the sources.inc file did it. I don't think you really need the .\ or the quotes though, just
Code: |
O_FILES =\
main.o \
picture.s |
should work. But if you do that, then every time you add a file to the project, you'll have to go type it in by hand there. It's a little bit of a hassle, but that's how I've always done it anyway.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#39468 - DKX - Sat Apr 09, 2005 7:10 am
I moved Resources.s into the same project folder, and now it compiles (and it appears in sources.inc). However, it coughs out "Resources.o: No such file or directory", and sure enough, Resources.o does not exist. Any thoughts on where it vanished to?
BTW, does this mean I don't have the ability to organize source files in the project folders, or is it limited to *.s files?
#39661 - DKX - Mon Apr 11, 2005 4:51 am
BUMP.
I hate bumping topics, but I still can't seem to figure out where Resources.o ends up. MSV6's output box says "Compiling ASM Sources" (something it didn't say before), but when it looks for Resources.o, it can't find it - and neither can a system-wide search. Main.c compiles without error, and Main.o is located with it. Do I need to do specify an output file somewhere?
Any and all help is greatly appreciated, as I'd really like to learn how to manage the essentials so I can move on to the actual coding.
#55725 - kentsimon - Sat Oct 01, 2005 12:19 am
DKX wrote: |
BUMP.
I hate bumping topics, but I still can't seem to figure out where Resources.o ends up. MSV6's output box says "Compiling ASM Sources" (something it didn't say before), but when it looks for Resources.o, it can't find it - and neither can a system-wide search. Main.c compiles without error, and Main.o is located with it. Do I need to do specify an output file somewhere?
Any and all help is greatly appreciated, as I'd really like to learn how to manage the essentials so I can move on to the actual coding. |
I am having the same issue, it appears that all of the .s files become a.out which is the default output filename for AS, I have not figured out how to force the output filenames I know -o defines the filename, but I have nmake errors whenever I try to change the rule for .s files to name the output.
Help!
anyone?
-Kent
#55759 - Cearn - Sat Oct 01, 2005 6:41 pm
In the assembly rules, try changing
to
Code: |
$(AS) $(SFLAGS) $< -o $@
|
What exactly is the error that nmake gives you?
#55811 - kentsimon - Sun Oct 02, 2005 4:52 pm
Cearn wrote: |
In the assembly rules, try changing
to
Code: | $(AS) $(SFLAGS) $< -o $@
|
What exactly is the error that nmake gives you? |
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
Generating Makefile Include...
Done!
NMAKE : fatal error U1100: macro '$@' is illegal in the context of batch rule '.s.o'
Stop.
Error executing NMAKE.
thanks for the help, I have no idea what could be wrong.
here are what I believe to be the relevant parts of the make I am using GBAForVS6
AS = "$(DEVKITDIR)\bin\arm-elf-as"
INCDIR = "$(DEVKITDIR)\lib\gcc\arm-elf\4.0.1\include"
INCDIR2 = "$(DEVKITDIR)\arm-elf\include"
SFLAGS = -I $(INCDIR2) -I $(INCDIR) -I C:\gbaprojects\include -mthumb-interwork
.s.o ::
@echo -------------------------
@echo Compiling Asm Sources...
@echo -------------------------
$(AS) $(SFLAGS) $< -o $@
-Kent
#55823 - wintermute - Sun Oct 02, 2005 9:16 pm
You'd be much better off switching to gnu make. Nmake doesn't really work well with gnu tools.
The example projects distributed with devkitARM provide some fairly standardised gnu makefiles which work well. There are also a number of posts around the forums which detail how to set up a makefile project with various versions of msvc.
#55842 - Cearn - Mon Oct 03, 2005 8:04 am
Quote: |
Code: | NMAKE : fatal error U1100: macro '$@' is illegal in the context of batch rule '.s.o'
<snip>
.s.o ::
@echo -------------------------
@echo Compiling Asm Sources...
@echo -------------------------
$(AS) $(SFLAGS) $< -o $@
|
|
Apparently, this rule is a batch rule (as error u1100 indicates). I think that's the work of the double colons, removing one of them may work.
wintermute is right about gnu make, it's easier to deal with and not MS specific. For how to set something up, see here and here. I should probably point out that VC 6 is rather nasty in that it creates all kinds of extra directories for every object/configuration you have whether you want them or not. If you don't want those, you'd have to remove them manually from the dsp file (all the Intermediate_Dir and Output_Dir thingies).
#55864 - kentsimon - Mon Oct 03, 2005 3:47 pm
Cearn wrote: |
Quote: | Code: | NMAKE : fatal error U1100: macro '$@' is illegal in the context of batch rule '.s.o'
<snip>
.s.o ::
@echo -------------------------
@echo Compiling Asm Sources...
@echo -------------------------
$(AS) $(SFLAGS) $< -o $@
|
|
Apparently, this rule is a batch rule (as error u1100 indicates). I think that's the work of the double colons, removing one of them may work.
wintermute is right about gnu make, it's easier to deal with and not MS specific. For how to set something up, see here and here. I should probably point out that VC 6 is rather nasty in that it creates all kinds of extra directories for every object/configuration you have whether you want them or not. If you don't want those, you'd have to remove them manually from the dsp file (all the Intermediate_Dir and Output_Dir thingies). |
I can handle most of the vs6 issues, that worked btw with the double colon thanks.
I have not followed those links yet, where can I get the gnu make?
-Kent
#55867 - Cearn - Mon Oct 03, 2005 3:56 pm
gnu make is included in MSYS. Install it and add its bin directory to your path. GNU makefiles are a little different in syntax from nmake's, you can get a manual here or here.
#55877 - wintermute - Mon Oct 03, 2005 6:07 pm
alternatively use the devkitPro windows installer found here, http://www.devkitpro.org/setup.shtml