GP32 [g++ & Sdl] Undefined Reference To `gpmain


Teal'c

Still Fresh
Joined
Jul 15, 2004
Messages
3
Greetings,

Well.. I'm having troubles to port a game to gp32.. let me explain:

I'm using GP32 Cross Toolchain for Linux to port a game (C++ and SDL) and i get this error when y try to link all source:

/usr/arm-thumb-elf/lib/libgpos.a(gpos_core.o): In function `GpKernelInitialize':
gpos_core.o(.text+0x2b4): undefined reference to `GpMain'


Do anyone know how i can fix this? Thanks.
 
Errr... maybe add a GpMain() function?

In normal C/C++ programs, the entry point to the program is main(). That's not the case when you're using gamepark's sdk, the entry point for your code must be called "GpMain".

The solution may be as easy as finding the main() function in the source you're compiling, and renaming it to GpMain.
 
Nope, i have a GpMain in the code :)

There's my gpmain.cpp:

Code:
#include <gpstdio.h>
#include <gpstdlib.h>
#include <gpgraphic.h>
#include <gpfont.h>

#include "gameplay.h"

void GpMain (void *argv)
{
        GamePlay test;
        test.Loop();
       
}

The class GamePlay uses SDL

I compiled many games with gcc.. but when i try to compile c++ programs with g++ i get that error...

i complied the source by:

Code:
arm-thumb-elf-g++ -Iinclude-gp32 -Isrc -Isrc/gb -I/usr/arm-thumb-elf/include/SDL -Iinclude-gp32 -I. -O2 -mtune=arm920 -DGFXST -DGP32 -Wuninitialized -Wno-import -Wchar-subscripts -Wformat -Wimplicit-int -Wimplicit-function-declaration -Wmultichar -Wreturn-type -Wswitch -Wunused -Wuninitialized -Wsign-compare -msoft-float -mthumb-interwork -DYYTEXT_POINTER=1 -DHAVE_LIBPNG=1 -DHAVE_LIBPTHREAD=1 -DHAVE_LIBZ=1 -DSTDC_HEADERS=1 -DHAVE_MALLOC_H=1 -DHAVE_STRINGS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_NETINET_IN_H=1 -D_REENTRANT -DSDL -DBKPT_SUPPORT -fno-exceptions -DC_CORE -c gpmain.cpp -o gpmain.o

and finally linked all by:

Code:
arm-thumb-elf-gcc -o test.elf crt0.o gpstart.o gpmain.o gameplay.o -L/usr/arm-thumb-elf/lib -Tlnkscript user_init.o -nostartfiles -lgpos -lgpsound -lgpmem -lgpgraphic -lgpfont -lSDL -ljpeg -lz -lm -lgpstdlib -lgpstdio -lgpstdlib -lstdc++
 
Aha, then it's probably a C++ name-mangling problem. Because GpMain is in a C++ file, it will be exported by g++ as xyzGpMain#32%!^&* or some such rubbish.

Possibly the solution is just to prototype GpMain as a C function, ie. above the implementation of GpMain, put
Code:
extern "C" {
void GpMain (void *argv);
}

Does that work?
 
I'm using a gpmain.cc too, and no extern "C" used, and it links ok.
Maybe that's not the problem, but try it.

Take a look at gpstart.c, there are some declarations and references to GpMain there, and i have a Main() function there too.

I think the sdk calls Main() and then GpMain() or somethink.

Aiken
 
Thanks guys, you really help me :)

Code:
extern "C"
{
#include <gpstdio.h>
#include <gpstdlib.h>
#include <gpgraphic.h>
#include <gpfont.h>
}

#include "gameplay.h"

void GpMain (void *argv)
{
       GamePlay test;
       test.Loop();
      
}

Now works fine :D thanks all!
 
Back
Top