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 > How can I link nds-file?

#119365 - Phantaseur - Thu Feb 22, 2007 1:16 pm

I have a problem creating simple hello world application. As I understand at first I need compile source and get object-file then link it and get elf-file, and then using objcopy get bin and nds files... What for such difficulties? Why can't I get nds-file after linking?

I have no problems with compilation

arm-eabi-g++ -mcpu=arm9tdmi -Wall -DARM9 -I/e/devkitPro/libnds/include/ -c helloworld.cpp

after this helloworld.o appears and I try to link it

/e/devkitPro/devkitarm/bin/arm-eabi-g++ -L/e/devkitPro/libnds/lib/ -lnds9 my.o -o helloworld.elf

but next output appears

helloworld.o: In function `main':
helloworld.cpp:(.text+0x7c): undefined reference to `vramSetBankC'
helloworld.cpp:(.text+0xa4): undefined reference to `consoleInitDefault'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-abort.o): In function `abort':
(.text+0xc): undefined reference to `_exit'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-exit.o): In function `exit':
(.text+0x28): undefined reference to `_exit'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
(.text+0x1c): undefined reference to `_sbrk'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-signalr.o): In function `_getpid_r':
(.text+0x8): undefined reference to `_getpid'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-signalr.o): In function `_kill_r':
(.text+0x38): undefined reference to `_kill'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-makebuf.o): In function `__smakebuf':
(.text+0xf4): undefined reference to `isatty'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-writer.o): In function `_write_r':
(.text+0x24): undefined reference to `_write'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-closer.o): In function `_close_r':
(.text+0x1c): undefined reference to `_close'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-fstatr.o): In function `_fstat_r':
(.text+0x20): undefined reference to `_fstat'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-lseekr.o): In function `_lseek_r':
(.text+0x24): undefined reference to `_lseek'
e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-readr.o): In function `_read_r':
(.text+0x24): undefined reference to `_read'
collect2: ld returned 1 exit status
make: *** [helloworld.elf] Error 1

As I know first two strings
helloworld.cpp:(.text+0x7c): undefined reference to `vramSetBankC'
helloworld.cpp:(.text+0xa4): undefined reference to `consoleInitDefault'
mean that there is no such functions in libnds, what else library need I load for these functions? And what mean other errors? What options need I use for successfull generating of nds-file?

Example of sourcecode of helloworld application I took here:
http://www.double.co.nz/nintendo_ds/nds_develop1.html

#119386 - NeX - Thu Feb 22, 2007 5:11 pm

You DO NOT want to compile like that. It takes ages. Instead, use ALT+1 in Programmers' Notepad.

#119390 - simonjhall - Thu Feb 22, 2007 5:17 pm

I seem to remember having trouble like this a while ago and it just 'went away' when I put spaces between -L and the libs directory.

It's obviously not finding the references to those functions, so either the compiler is generating the wrong function name (ie it could be mangling the function name) or the link library can't be found.

What happens when you compile the file with gcc instead of g++?
_________________
Big thanks to everyone who donated for Quake2

#119397 - wintermute - Thu Feb 22, 2007 6:06 pm

Phantaseur wrote:

after this helloworld.o appears and I try to link it

/e/devkitPro/devkitarm/bin/arm-eabi-g++ -L/e/devkitPro/libnds/lib/ -lnds9 my.o -o helloworld.elf

but next output appears

helloworld.o: In function `main':
helloworld.cpp:(.text+0x7c): undefined reference to `vramSetBankC'
helloworld.cpp:(.text+0xa4): undefined reference to `consoleInitDefault'


This is caused by specifying the library before the object files.

Quote:

e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.1/../../../../arm-eabi/lib\libc.a(lib_a-abort.o): In function `abort':
(.text+0xc): undefined reference to `_exit'

...


These are caused by not telling g++ you want to link nds code.

The actual command line you want is

Code:

arm-eabi-g++ -specs=ds_arm9.specs -L/e/devkitPro/libnds/lib/  my.o -lnds9 -o helloworld.elf


Chris is currently in the process of updating his tutorials for latest toolchain and libnds so you might have a bit of trouble getting things to work.

For now I'd recommend starting with the dev-scene tutorials Dovoto has been beavering on.

http://www.dev-scene.com/NDS/Tutorials
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog