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.

C/C++ > Building and linking ASM (.S) files

#81346 - Crs - Fri Apr 28, 2006 4:23 pm

Hi guys,

Should be simple one.. I'm having a bit of trouble linking an asm file to my project.

to compile it I am using:
arm-elf-as -mthumb-interwork -o <FILE.O> <FILE>.S

this produces the object '.o' file

((and compiling my normal c files like: arm-elf-g++ -O2 -g -mcpu=arm7tdmi -mthumb-interwork -c <FILE>.C))

The functions in the asm file are declared as extern in the c file but when calling either one I get an undefined reference.

Am I missing anything or should I get posting some code?

Thanks

Chris.
_________________
www.hazardball.com

#81349 - Lord Graga - Fri Apr 28, 2006 4:41 pm

First of all, it seems like that you are using .bat files - use Makefiles, they are a thousand times more dynamic and will make things quite a lot easier for you.

How are you linking everything?

#81351 - wintermute - Fri Apr 28, 2006 5:02 pm

Compiling files with g++ generates C++ linkage (i.e. the names are mangled). In order to call functions in assembly files you need to specify them with C linkage using extern "C". If you want to call functions in the C files from assembly then you also need to use extern "C" on your function declarations.

You can avoid all this by using gcc rather than g++ if you're writing standard C.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#81363 - Crs - Fri Apr 28, 2006 6:59 pm

Bingo!

I really should have known that, *smack head* appreciated wintermute.

Chris.
_________________
www.hazardball.com

#81365 - tepples - Fri Apr 28, 2006 7:13 pm

Crs wrote:
((and compiling my normal c files like: arm-elf-g++ -O2 -g -mcpu=arm7tdmi -mthumb-interwork -c <FILE>.C))

Both the use of g++ and the use of a capital C filename extension tend to trigger the compiler to treat a source code file as C++ instead of C.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#81366 - Crs - Fri Apr 28, 2006 7:18 pm

interesting, the case of the extension really makes that difference? I knew naming .c instead of .cpp made the compiler treat the source different but did not know uppercase/lowercase had anything to do with it. Nice note thanks.
_________________
www.hazardball.com

#81367 - tepples - Fri Apr 28, 2006 7:23 pm

Crs wrote:
interesting, the case of the extension really makes that difference?

Yes. The GNU operating system is a clone of the UNIX operating system, and both GNU and UNIX have historically used case sensitive file systems. FAT as implemented in Microsoft Windows, on the other hand, is case insensitive but case preserving.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#81424 - chishm - Sat Apr 29, 2006 2:47 am

tepples wrote:
FAT as implemented in Microsoft Windows, on the other hand, is case insensitive but case preserving.

FAT itself (8.3 names) is not case preserving, VFAT (long file names) is.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#81431 - wintermute - Sat Apr 29, 2006 3:41 am

tepples wrote:
Crs wrote:
((and compiling my normal c files like: arm-elf-g++ -O2 -g -mcpu=arm7tdmi -mthumb-interwork -c <FILE>.C))

Both the use of g++ and the use of a capital C filename extension tend to trigger the compiler to treat a source code file as C++ instead of C.


good catch, forgot about that one.

chishm wrote:
tepples wrote:
FAT as implemented in Microsoft Windows, on the other hand, is case insensitive but case preserving.

FAT itself (8.3 names) is not case preserving, VFAT (long file names) is.


That's not relevant. The filesystem is case insensitive so specifying an upper case letter on the command line is enough.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#81432 - tepples - Sat Apr 29, 2006 3:53 am

chishm wrote:
tepples wrote:
FAT as implemented in Microsoft Windows, on the other hand, is case insensitive but case preserving.

FAT itself (8.3 names) is not case preserving, VFAT (long file names) is.

"FAT as implemented in Microsoft Windows" is VFAT.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.