gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Makefile Question

#67977 - Rinky - Sat Jan 21, 2006 9:20 pm

I have to say that despite having been programming since I was a very young kid (on all manner of systems) makefiles always give me grief.

I'm stuck. I tend to use the DS makefile examples from DoubleC

For example:
Code:

# Makefile for demo1.nds
# DoubleC [Removed the email address for posting]
NDSLIB_INCLUDE=$(DEVKITPRO)/libnds/include
NDSLIB_LIB=$(DEVKITPRO)/libnds/lib

all: demo1.nds.gba

arm7_main.o: arm7_main.cpp
   arm-elf-g++ -g -Wall -O2 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM7 -c arm7_main.cpp -oarm7_main.o

arm7.elf: arm7_main.o
   arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm7.specs arm7_main.o -L$(NDSLIB_LIB) -lnds7 -oarm7.elf

arm7.bin: arm7.elf
   arm-elf-objcopy -O binary arm7.elf arm7.bin

arm9_main.o: arm9_main.cpp
   arm-elf-g++ -g -Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -I$(NDSLIB_INCLUDE) -DARM9 -c arm9_main.cpp -oarm9_main.o

arm9.elf: arm9_main.o
   arm-elf-g++ -g -mthumb-interwork -mno-fpu -specs=ds_arm9.specs arm9_main.o -L$(NDSLIB_LIB) -lnds9 -o arm9.elf

arm9.bin: arm9.elf
   arm-elf-objcopy -O binary arm9.elf arm9.bin

demo1.nds: arm7.bin arm9.bin
   ndstool -c demo1.nds -9 arm9.bin -7 arm7.bin

demo1.nds.gba: demo1.nds
   dsbuild demo1.nds -o demo1.nds.gba

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


(and expand on them as needed) but I can't figure out how to link in an assembly .s file.

One of my test ARM9 programs declares an extern reference to a bunch of assembly in a .s file. But the compiler (understandably) says it can't find the code.

Would anyone mind putting me out of my misery? :)

#67989 - DekuTree64 - Sat Jan 21, 2006 10:26 pm

Sounds like your makefile is fine. I think the problem is that the .cpp file is expecting all the symbol names to be mangled, but .s files output symbols as-is (C-style).

Try declaring the functions as extern "C" in the .cpp file, like
Code:
extern "C" int Function(int arg);

Or for a whole bunch of them, and to make it compile in both .c and .cpp files, you can do like
Code:
#ifdef __cplusplus
extern "C" {
#endif

extern int Function1(int arg);
extern int Function2(int arg);
extern int Function3(int arg);

#ifdef __cplusplus
}
#endif

__cplusplus is defined automagically by the compiler when building .cpp files. The second method is better to use in headers so you can mix C and C++ if you feel like it. I usually only use the first style if I'm externing one or two functions in a single .cpp file.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku