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 > trouble compiling with libnds and devkitpro

#126592 - yaazz - Wed Apr 25, 2007 1:35 am

Hello all, I am new at your site, and am having trouble compiling with libnds. I use Kubuntu, and this is the output from the terminal
Quote:

afreddin@afreddin-desktop:~/Manual/DSspace$ make
Splash.bin
bin2s /home/afreddin/Manual/DSspace/data/Splash.bin | arm-eabi-as -mthumb -mthumb-interwork -o Splash.o
echo "extern const u8" `(echo Splash.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo Splash.bin | tr . _)`.h
echo "extern const u8" `(echo Splash.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo Splash.bin | tr . _)`.h
echo "extern const u32" `(echo Splash.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo Splash.bin | tr . _)`.h
StarField.bin
bin2s /home/afreddin/Manual/DSspace/data/StarField.bin | arm-eabi-as -mthumb -mthumb-interwork -o StarField.o
echo "extern const u8" `(echo StarField.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo StarField.bin | tr . _)`.h
echo "extern const u8" `(echo StarField.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo StarField.bin | tr . _)`.h
echo "extern const u32" `(echo StarField.bin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo StarField.bin | tr . _)`.h
linking DSspace.elf
/home/afreddin/devkitpro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib/thumb/ds_arm9_crt0.o: In function `CIDLoop':
ds_arm9_crt0.s:(.init+0x218): undefined reference to `main'
collect2: ld returned 1 exit status
make[1]: *** [/home/afreddin/Manual/DSspace/DSspace.elf] Error 1
make: *** [build] Error 2
afreddin@afreddin-desktop:~/Manual/DSspace$


As you can see, it ends when trying to link DSspace.elf, with DSspace being the name of the directory. Anyone know how to fix this? thanks

#126594 - tepples - Wed Apr 25, 2007 2:03 am

What .c files are inside the ARM9 source folder? Does any of them have a main() function?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#126604 - yaazz - Wed Apr 25, 2007 2:47 am

Quote:

afreddin@afreddin-desktop:~/Manual/DSspace$ ls -l
total 44
drwxr-xr-x 2 afreddin afreddin 4096 2007-04-24 09:25 build
drwxr-xr-x 2 afreddin afreddin 4096 2007-04-24 09:15 data
drwxr-xr-x 2 afreddin afreddin 4096 2007-04-24 05:09 gfx
-rw-r-xr-- 1 afreddin afreddin 1101 2007-04-24 09:17 main.cpp
-rw-r-xr-- 1 afreddin afreddin 1097 2007-04-24 04:58 main.cpp~ *Backup
-rw-r--r-- 1 afreddin afreddin 5147 2007-04-24 09:12 Makefile
-rw-r--r-- 1 afreddin afreddin 5291 2006-09-23 19:16 Makefile~ *backup
-rw-r--r-- 1 afreddin afreddin 98 2007-04-23 11:24 Splash_bin.h
-rw-r--r-- 1 afreddin afreddin 107 2007-04-23 11:24 StarField_bin.h

#126605 - Lick - Wed Apr 25, 2007 2:56 am

Could you post your Makefile?
_________________
http://licklick.wordpress.com

#126609 - yaazz - Wed Apr 25, 2007 3:12 am

the makefile came from this tutorial
http://www.double.co.nz/nintendo_ds/nds_develop1.html

Quote:

#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
endif

include $(DEVKITARM)/ds_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := gfx source data
INCLUDES := include build

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork

# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
# *insists* it has a FPU or VFP, and it won't take no for an answer!
CFLAGS := -g -Wall -O2\
-mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9


#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES := $(BINFILES:.bin=.o) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba


#---------------------------------------------------------------------------------
else

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds : $(OUTPUT).arm9
$(OUTPUT).arm9 : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)

#---------------------------------------------------------------------------------
%.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)


-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

#126617 - Lick - Wed Apr 25, 2007 3:26 am

Try avoiding that tutorial, since it's really old and most of the time incompatible with the latest libraries.

Go here and download the official examples. In the examples you will find template-projects, that you can copy and rename to your own project.
  • /templates/arm9 - use this if you only want to program the arm9 cpu. (You should use this one!)
  • /templates/arm9lib - use this if you want to create library (lib*.a) files.
  • /templates/combined - advanced template, code for arm9 cpu and arm7 cpu.
  • /templates/dldi - for writing DLDI drivers.

You should use the first one. Just copy "/templates/arm9" from the examples and rename it to "myprojectname".

The examples also provide all the necessary basics like display graphics, capturing input and playing sound. Just examine the code, copy it, customize it and learn it.
_________________
http://licklick.wordpress.com

#126626 - yaazz - Wed Apr 25, 2007 4:46 am

I replaced the source in main.c with my main.cpp file, and now it is starting to compile, but ends when it says somethign should be a void, instead of an INT

Quote:

#include <nds.h>
#include "StarField_bin.h"
#include "Splash_bin.h"


void initVideo();
void initBackgrounds();
void displaySplash();
void displayStarField();

int main(void){
//turn on 2d core
powerON(POWER_ALL_2D);

//turn on the 2d core
irqInit();
irqSet(IRQ_VBLANK,0);

initVideo();
initBackgrounds();

displaySplash();
displayStarField();
return 0;
}

void initVideo(){
/*map vram to display a BG on each screen, and then give some memory for sprites */
vramSetMainBanks( //map A and B to main background memory, this gives us 256KB which is good for 16bit graphics
VRAM_A_MAIN_BG_0x6000000,
VRAM_B_MAIN_BG_0x6020000,
// map c to sub background memory
VRAM_C_SUB_BG_0x6200000,
//map d to lcd free space
VRAM_D_LCD);

//set bank E for use with sprites, this gives us 64KB to use for sprites, which is the max space 1024 tiles takes up in 256 color mode
vramSetBankE(VRAM_E_MAIN_SPRITE);

//set the video mode on the main screen
videoSetMode( MODE_5_2D | DISPLAY_SPR_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_1D);

//set the video mode on the sub screen
videoSetModeSub ( MODE_5_2D | DISPLAY_BG3_ACTIVE );


}

void initBackgrounds(){
//setup extended rotation backgrounds on main as a 16bit color background
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
//attributes of the affine transformation matrix
BG3_XDX = 1 << 8; //scale X
BG3_XDY = 0; //Rotation X
BG3_YDX = 0; //Rotation Y
BG3_YDY = 1 << 8; //Rotation Y
BG3_CX = 0; //Translation X
BG3_CY = 0; //Translation Y

//setup extended rotation backgrounds on sub as a 16bit color background
SUB_BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
//attributes of the affine transformation matrix
SUB_BG3_XDX = 1 << 8; //scale X
SUB_BG3_XDY = 0; //Rotation X
SUB_BG3_YDX = 0; //Rotation Y
SUB_BG3_YDY = 1 << 8; //Rotation Y
SUB_BG3_CX = 0; //Translation X
SUB_BG3_CY = 0; //Translation Y
}

void displaySplash(){
dmaCopy(Splash_bin,BG_BMP_RAM_SUB(0),Splash_bin_size);
//the memory for sub BG is BG_BMP_RAM_SUB(0)
}

void displayStarField(){
dmaCopy(StarField_bin,BG_BMP_RAM(0),StarField_bin_size);
//the memory for main BG is BG_BMP_RAM_(0)
}




and here is the output
Quote:

afreddin@afreddin-desktop:~/nds-examples-20070327/templates/arm9$ make
main.cpp
arm-eabi-g++ -MMD -MP -MF /home/afreddin/nds-examples-20070327/templates/arm9/build/main.d -g -Wall -O2 -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/home/afreddin/nds-examples-20070327/templates/arm9/include -I/home/afreddin/devkitpro/libnds/include -I/home/afreddin/nds-examples-20070327/templates/arm9/build -DARM9 -fno-rtti -fno-exceptions -c /home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp -o main.o
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp: In function 'void displaySplash()':
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp:72: error: invalid conversion from 'int' to 'void*'
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp:72: error: initializing argument 2 of 'void dmaCopy(const void*, void*, uint32)'
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp: In function 'void displayStarField()':
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp:77: error: invalid conversion from 'int' to 'void*'
/home/afreddin/nds-examples-20070327/templates/arm9/source/main.cpp:77: error: initializing argument 2 of 'void dmaCopy(const void*, void*, uint32)'
make[1]: *** [main.o] Error 1
make: *** [build] Error 2

#126627 - Lick - Wed Apr 25, 2007 4:47 am

BG_BMP_RAM(0) -> (void*)BG_BMP_RAM(0)

BG_BMP_RAM_SUB(0) -> (void*)BG_BMP_RAM_SUB(0)
_________________
http://licklick.wordpress.com

#126629 - yaazz - Wed Apr 25, 2007 4:58 am

Yeah I thought that was the problem, since BG_BMP_RAM_SUB(0) is an address, but when Ido this, it tells me "undefined reference to Splash_bin, and "undefined reference to Splash_bin_size" (i have starfield commented out at the moment.


Splash_bin, is of course a graphics file, and the .h looks like this
Quote:

extern const u8 Splash_bin_end[];
extern const u8 Splash_bin[];
extern const u32 Splash_bin_size;


This is out of the other libnds tutorial as you have probably guessed

#126630 - Lick - Wed Apr 25, 2007 5:11 am

Remember what I said earlier, about the official templates? (If not, you can always scroll up, hehe.) It's not only the code in "main.cpp" that matters. It's the whole directory structure + Makefile. As you can see, if those aren't compatible with each other, the (linking) errors will pop out like spam.

So once again, you're better off using the official templates as base.
_________________
http://licklick.wordpress.com