GP32 Swi_mmu_change Linking


ThomasS

Still Fresh
Joined
Apr 8, 2003
Messages
22
I surprisingly succeeded to compile Mr. Spiv's h3.tgz/'rotozoomer' in a very short time. But I had to change the compiler in my Makefile from g++ to gcc because otherwise I got a linker error saying 'undefined reference to swi_mmu_change() and ARMDisableInterrupt'.

With a text search I recognized that:
1) swi_mmu_change() is only in libgpstdlib.a, but not in it's c++ equivalent (in no other .a file at all)
2) same with ARMDisableInterrupt()

I want to use swi_mmu_change in my own code, but I always write c++ style (I don't speak about classes here, I just don't declare all variables at the beginning, I use functions with same name but different types etc.)

That'll be hell if I'd have to change all my .cpp files to .c stylish ones just to use functions like swi_mmu_change, ARMDisableInterrupt, EnableCache() etc. (And I am not that asm expert to use asm volatiles instead of the functions.)

So I wanted to be clever and I just did one single 'graphics.c' file (and kept the other files .cpp). But now I get undefined references to all my functions from graphics.c. (The linker call has still _all_ .o files, so should be still correct.) Is it possible that graphics.o (in c style) is incompatible with ('unreadable from') all the other .o (in c++ style) ??? I never heard about something like that, I always thought one can link whatever output .o files one likes (asm, pascal, c, c++ etc.....)

Is there anything I can do to get either swi_mmu_change() etc. working _without_ plain C code or to get working combined c/c++ code?
 
you could try using extern:
Code:
extern "C" {
          (return type) swi_mmu_change();
          (return type) ARMDisableInterrupt();
          etc....
}

This will let you use c libraries in c++.

Just put it near your includes and such in your .cpp that calls it.
Or you can put it in your header file and be sure to include it where you need it.

Bobby
 
Ah thanks, that worked great and solved all problems. Now I even know why I always had to include that gpsdk.h everywhere in other programs - it contains such a extern "C" for some functions in case of _cplusplus.
 
Back
Top