GP2X Beginner's Request


I just linked those libraries as I'll use them later, and my SD is quite empty, so need to fill it up :D
I'm not sure about those errors as I've just started using SDL for the first time, but I'll have a look at them tomorrow morning, not feeling great just now and I'm away to my bed :(
 
Thanks! That really helped me get started. I'm kind of puzzled about why you need the static linking, as most of the released stuff seems to be dynamically linked to SDL, but if I remove the '-static' the program doesn't run. I guess it doesn't matter for now at least, and hopefully it's not an issue by the time I actually have something worth running anyway :)
 
Any ideas? What am I doing wrong? It clearly seems like it's related to SDL_image and SDL_mixer... Thanks in advance.
Try playing with the lib order in the makefile (usually putting -lSDL_mixer etc before -lSDL sorts out things like that).

Thanks! That really helped me get started. I'm kind of puzzled about why you need the static linking, as most of the released stuff seems to be dynamically linked to SDL, but if I remove the '-static' the program doesn't run. I guess it doesn't matter for now at least, and hopefully it's not an issue by the time I actually have something worth running anyway :)
The libs on the device were compiled with gcc 2.95, and so if you want to dynamically link with those then your app must also be compiled with the same version of gcc. Most people are using gcc 4, which means the libs must also be compiled with gcc 4. You can still link dynamically with those libs, but then you must copy them to the device (like NK's apps) and as you've probably seen a lot of people are having problems with those apps and the libs not installing correctly. Using static linking means you get a nice clean app thats easy to install and run with no lib problems, but the downside is your app is bigger due to including the libs (but if you run strip over it the size is cut down by a decent amount).
 
Last edited by a moderator:
Try playing with the lib order in the makefile (usually putting -lSDL_mixer etc before -lSDL sorts out things like that).
Thanks. I've tried it and got better results. Now I'm not getting undefined references to other SDL functions, but there are undefined references to functions from which SDL_mixer and SDL_image depend, like these:
Code:
C:/Informatica/devkitPro/devkitGP2X/lib\libSDL_mixer.a(music.o): In function `music_mixer':
music.c:(.text+0x2c8): undefined reference to `VC_WriteBytes'
music.c:(.text+0x598): undefined reference to `VC_WriteBytes'
music.c:(.text+0x6fc): undefined reference to `SMPEG_playAudio'
After this, I thought I had to link to the libraries which contain these functions, so I did it. Even though I'm not sure if this is correct, the fact is that there are less errors than before. But still not working... Here is the LIBS part of my Makefile:
Code:
LIBS =  -static -L"C:/Informatica/devkitPro/devkitGP2X/lib" -lSDL_mixer -lvorbisfile -lvorbis -logg -lsmpeg -lmikmod -lpthread -lSDL_image -ljpeg -lpng12 -lzip -lSDL -lSDLmain
You see "-lpthread", for example? If I remove it I get tons of messages like these:
Code:
C:/Informatica/devkitPro/devkitGP2X/lib\libmikmod.a(mplayer.o): In function `Player_SetVolume':
mplayer.c:(.text+0x99f0): undefined reference to `pthread_mutex_lock'
mplayer.c:(.text+0x9a50): undefined reference to `pthread_mutex_unlock'
Sorry for adding so much code here, but I think that's the best way I know to explain what's happening...
 
Last edited by a moderator:
I got SDL working with devkitGP2X and the libs at http://gp2x.org/gp2x/libs/

You need to edit a few things to get it working, so heres a quick guide from the top of my head. I will write a proper one later on and add it to the GP2X User Guide.

1. Install devkitGP2X
2. Extract gp2xlibs.tar.gz and then copy the 'gp2x' folder (its a few folders in) containing bin, include etc to c:/devkitGP2X/. It should ask to overwrite some folders if its copied correctly.
3. Rename '/devkitGP2X/bin/arm-open2x-linux-sdl-config' to 'arm-linux-sdl-config'. This isnt really needed to be done if you edit the below makefile but I done this while getting things working :)
4. Open '/devkitGP2X/bin/arm-linux-sdl-config' in a text editor and change the following:

prefix=/opt/local/gp2x
to
C:/devkitGP2X

4. Use the following makefile

Code:
CROSS_COMPILE = C:/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitGP2X/bin/arm-linux-
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
STRIP = $(CROSS_COMPILE)strip

CFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
CXXFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
LIBS = `$(SDL_BASE)sdl-config --libs`

SDLTEST_TARGET = sdltest.gpe
SDLTEST_OBJS = main.o

ALL_TARGETS = $(SDLTEST_TARGET) 

all : $(ALL_TARGETS)

$(SDLTEST_TARGET) : $(SDLTEST_OBJS)
	$(CXX) $(LDFLAGS) -o $(SDLTEST_TARGET) $(SDLTEST_OBJS) $(LIBS)
	$(STRIP) $(SDLTEST_TARGET)

clean:
	rm -f $(ALL_TARGETS) *.o *~

5. Compile your code with make and you should have a 'sdltest.gpe' which can now be run on your GP2X.

This is off the top of my head so it may not work as I have missed something out. When I get a chance later I will write up a proper guide.

update - thanks to rhk for his makefile thats used above :)
 
Thanks for all the great info - I've got Kalakian's example up and running on my Gp2x :)

One question though - does anyone know how to exit their program and get back to the OS screen? Even my do-nothing program which returns 0 at the top of main() just hangs on exit....
 
I got SDL working with devkitGP2X and the libs at http://gp2x.org/gp2x/libs/
Thanks a lot for these instructions.

But again, the linker doesn't find SDL_mixer and SDL_image functions:
Code:
C:/devkitGP2X/bin/arm-linux-g++ -static -o tilematch.gpe Tilematch.o Cursor.o M
tor.o MotorTilematch.o Peca.o Puntuacions.o Text.o `C:/devkitGP2X/bin/arm-linux
sdl-config --libs`
Cursor.o: In function `Cursor::Cursor(SDL_Surface*)':
Cursor.cpp:(.text+0x10): undefined reference to `IMG_Load'
Cursor.o: In function `Cursor::Cursor(SDL_Surface*)':
Cursor.cpp:(.text+0x1f4): undefined reference to `IMG_Load'
MotorTilematch.o: In function `MotorTilematch::Finalitza()':
MotorTilematch.cpp:(.text+0x10): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x1c): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x28): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x34): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x40): undefined reference to `Mix_FreeChunk'
"IMG_Load" call is from SDL_image and "Mix_FreeChunk" is from SDL_mixer. I have done all you said. Even the folders have the same name and are in the same location.

Here is my Makefile (same as yours, but with extra OBJS):
Code:
CROSS_COMPILE = C:/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitGP2X/bin/arm-linux-
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
STRIP = $(CROSS_COMPILE)strip

CFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
CXXFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
LIBS = `$(SDL_BASE)sdl-config --libs` -lSDL_mixer -lSDL_image -lSDLmain -lSDL

TARGET = tilematch.gpe
OBJS = Tilematch.o Cursor.o Motor.o MotorTilematch.o Peca.o Puntuacions.o Text.o

ALL_TARGETS = $(TARGET)

all: $(ALL_TARGETS)

$(TARGET): $(OBJS)
    $(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
    $(STRIP) $(TARGET)
I've added "-lSDL_mixer -lSDL_image -lSDLmain -lSDL" to LIBS, even though I suspect "sdl-config --libs" does it for me, with no luck.

Btw, I'm using CygWin's make. Same happens using MinSys' one, and it doesn't work for me using DevC++'s one.

Edit: Doing this "LIBS = -lSDL_mixer -lSDL_image `$(SDL_BASE)sdl-config --libs`" instead of this "LIBS = `$(SDL_BASE)sdl-config --libs` -lSDL_mixer -lSDL_image" results in lots of undefined references to calls from which SDL_mixer and SDL_image depend.
 
Last edited by a moderator:
I got SDL working with devkitGP2X and the libs at http://gp2x.org/gp2x/libs/
Thanks a lot for these instructions.

But again, the linker doesn't find SDL_mixer and SDL_image functions:
Code:
C:/devkitGP2X/bin/arm-linux-g++ -static -o tilematch.gpe Tilematch.o Cursor.o M
tor.o MotorTilematch.o Peca.o Puntuacions.o Text.o `C:/devkitGP2X/bin/arm-linux
sdl-config --libs`
Cursor.o: In function `Cursor::Cursor(SDL_Surface*)':
Cursor.cpp:(.text+0x10): undefined reference to `IMG_Load'
Cursor.o: In function `Cursor::Cursor(SDL_Surface*)':
Cursor.cpp:(.text+0x1f4): undefined reference to `IMG_Load'
MotorTilematch.o: In function `MotorTilematch::Finalitza()':
MotorTilematch.cpp:(.text+0x10): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x1c): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x28): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x34): undefined reference to `Mix_FreeChunk'
MotorTilematch.cpp:(.text+0x40): undefined reference to `Mix_FreeChunk'
"IMG_Load" call is from SDL_image and "Mix_FreeChunk" is from SDL_mixer. I have done all you said. Even the folders have the same name and are in the same location.

Here is my Makefile (same as yours, but with extra OBJS):
Code:
CROSS_COMPILE = C:/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitGP2X/bin/arm-linux-
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
STRIP = $(CROSS_COMPILE)strip

CFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
CXXFLAGS = `$(SDL_BASE)sdl-config --cflags` -O2 -Wall -Werror
LIBS = `$(SDL_BASE)sdl-config --libs` -lSDL_mixer -lSDL_image -lSDLmain -lSDL

TARGET = tilematch.gpe
OBJS = Tilematch.o Cursor.o Motor.o MotorTilematch.o Peca.o Puntuacions.o Text.o

ALL_TARGETS = $(TARGET)

all: $(ALL_TARGETS)

$(TARGET): $(OBJS)
    $(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
    $(STRIP) $(TARGET)
I've added "-lSDL_mixer -lSDL_image -lSDLmain -lSDL" to LIBS, even though I suspect "sdl-config --libs" does it for me, with no luck.

Btw, I'm using CygWin's make. Same happens using MinSys' one, and it doesn't work for me using DevC++'s one.

Edit: Doing this "LIBS = -lSDL_mixer -lSDL_image `$(SDL_BASE)sdl-config --libs`" instead of this "LIBS = `$(SDL_BASE)sdl-config --libs` -lSDL_mixer -lSDL_image" results in lots of undefined references to calls from which SDL_mixer and SDL_image depend.

I had exactly the same problem, and I ended up ditching all references to SDL_mixer and SDL_image from my program, just to see if it would work. It did work OK without these two libs.

Sorry I can't offer more help. I'm going to have a look at it again later on tonight, if I get time.
 
Last edited by a moderator:
The libs on the device were compiled with gcc 2.95, and so if you want to dynamically link with those then your app must also be compiled with the same version of gcc. Most people are using gcc 4, which means the libs must also be compiled with gcc 4. You can still link dynamically with those libs, but then you must copy them to the device (like NK's apps) and as you've probably seen a lot of people are having problems with those apps and the libs not installing correctly. Using static linking means you get a nice clean app thats easy to install and run with no lib problems, but the downside is your app is bigger due to including the libs (but if you run strip over it the size is cut down by a decent amount).

Ah, of course, I should have realized that. :)
 
Last edited by a moderator:
I had exactly the same problem, and I ended up ditching all references to SDL_mixer and SDL_image from my program, just to see if it would work. It did work OK without these two libs.

Sorry I can't offer more help. I'm going to have a look at it again later on tonight, if I get time.
At least, it's nice to see I'm not alone... :) Please, tell us if you succeed!
 
Last edited by a moderator:
I can't build a binary file for GP2X with SDL_mixer and SDL_image, but now that I have a GP2X, I've tested my code removing any references to these two libraries and it works! Thanks very much for your help!
 
I'm going round and round in circles here! Certainly not a guru with this stuff, but no noob either (been knocking out GBA homebrew for a year or so using all sorts of stuff: devkitPro, VisualHAM/HAMLib, etc). I haven't actually ordered a GP2X, but it's under serious consideration as I don't think developing for my Nintendo DS is going to be as fun as it is for the GBA (all that RCA encryption and PassMe hacks).

If I can get this to work I am completely willing to write a detailed bullet-proof "How To" for the Wiki, so help, please (writing software documentation is one of the things I do for a living)!

So far I have:

1. Installed the complete devkitPro on WindowsXP Pro to c:\devkitPro using the installer (it's working e.g. I can compile the GBA examples).

2. Installed devkitGP2X to C:\devkitPro\devkitGP2X.

3. Setup devkitGP2X in a similar manner to "Manual Setup" instructions on http://www.devkitpro.org/setup.shtml, including creating a System Environment Variable called "DEVKITGP2X" with a value of "/c/devkitPro/devkitGP2X".

4. Copied the contents of the opt\local\gp2x (\bin, \include, \info, \lib, \man, \share) folder from the gp2xlibs.tar.gz file downloaded from http://gp2x.org/gp2x/libs/ to C:\devkitPro\devkitGP2X.

5. Edited the file C:\devkitPro\devkitGP2X\bin\arm-open2x-linux-sdl-config replacing "prefix=/opt/local/gp2x" on line number 3 with "prefix=C:/devkitPro/devkitGP2X".

6. Created a new project called "gp2x_001" in C:\devkitPro\examples\gp2x\gp2x_001 using Programmers Notepad that contains 2 files: Makefile and source\main.c.

Makefile
Slightly modified version of that given by Guyfawkes, because of the setup folders for devkitPro and not renaming arm-open2x-linux-sdl-config file.

Code:
CROSS_COMPILE = C:/devkitPro/devkitGP2X/bin/arm-linux-
SDL_BASE = C:/devkitPro/devkitGP2X/bin/
LDFLAGS = -static

CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
STRIP = $(CROSS_COMPILE)strip

CFLAGS = `$(SDL_BASE)arm-open2x-linux-sdl-config --cflags` -O2 -Wall -Werror
CXXFLAGS = `$(SDL_BASE)arm-open2x-linux-sdl-config --cflags` -O2 -Wall -Werror
LIBS = `$(SDL_BASE)arm-open2x-linux-sdl-config --libs`

SDLTEST_TARGET = sdltest.gpe
SDLTEST_OBJS = main.o

ALL_TARGETS = $(SDLTEST_TARGET) 

all : $(ALL_TARGETS)

    $(SDLTEST_TARGET) : $(SDLTEST_OBJS)
    $(CXX) $(LDFLAGS) -o $(SDLTEST_TARGET) $(SDLTEST_OBJS) $(LIBS)
    $(STRIP) $(SDLTEST_TARGET)

clean:
    rm -f $(ALL_TARGETS) *.o *~

main.c
Kalakians example code from earlier in this thread.

Code:
#include "SDL.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8

int main(int argc, char *argv[]) {
    SDL_Surface *screen;
    Uint8       *p;
    int         x = 10; //x coordinate of our pixel
    int         y = 20; //y coordinate of our pixel
    
    /* Initialize SDL */
    SDL_Init(SDL_INIT_VIDEO);
    
    /* Initialize the screen / window */
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
    
    for(int iy = 0; iy < 10; iy++)
    {
        for(int ix = 0; ix < 10; ix++)
        {
            /* Make p point to the place we want to draw the pixel */
            p = (Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel;
            
            /* Draw the pixel! */
            *p=0xff;
        }
    }
    
    /* update the screen (aka double buffering) */
    SDL_Flip(screen);
    while(1);
}

Here's where the trouble starts. Here's the output from the compiler. Where and how is the required rule specified? What have I missed out in my setup?

Code:
> "make" 
"make": *** No rule to make target `sdltest.gpe', needed by `all'.  Stop.

> Process Exit Code: 2
 
Last edited by a moderator:
Here's where the trouble starts. Here's the output from the compiler. Where and how is the required rule specified? What have I missed out in my setup?

Code:
> "make" 
"make": *** No rule to make target `sdltest.gpe', needed by `all'.  Stop.

> Process Exit Code: 2
Your Makefile looks very similar to Guyfawkes' one but I'm sure it's not a problem of the way you've setup the DevKit. In fact, I'm almost sure your problems are related with tabs and spaces.

On these lines
Code:
    $(SDLTEST_TARGET) : $(SDLTEST_OBJS)
   $(CXX) $(LDFLAGS) -o $(SDLTEST_TARGET) $(SDLTEST_OBJS) $(LIBS)
   $(STRIP) $(SDLTEST_TARGET)
I think that the first one shouldn't include spaces and last two should be tabbed once (each).
 
Last edited by a moderator:
Makefiles are very senstive to spacing and html is not good at that. The Makefile should not have any spaces at the beginning the SDLTEST_TARGET line. The 2 lines after that must start with one TAB character, no spaces.

Code:
...
all : $(ALL_TARGETS)

$(SDLTEST_TARGET) : $(SDLTEST_OBJS)
    $(CXX) $(LDFLAGS) -o $(SDLTEST_TARGET) $(SDLTEST_OBJS) $(LIBS)
    $(STRIP) $(SDLTEST_TARGET)
...

Here's where the trouble starts. Here's the output from the compiler. Where and how is the required rule specified? What have I missed out in my setup?

Code:
> "make" 
"make": *** No rule to make target `sdltest.gpe', needed by `all'.  Stop.

> Process Exit Code: 2
 
Last edited by a moderator:
Thanks for all the great info - I've got Kalakian's example up and running on my Gp2x :)

One question though - does anyone know how to exit their program and get back to the OS screen? Even my do-nothing program which returns 0 at the top of main() just hangs on exit....

Im just copying what everyone else is doing atm, run the game with a script. Something like this...

Code:
/mnt/sd/GAME_PATH/GAME_EXE

cd /usr/gp2x
./gp2xmenu

Just remember to keep the carrier returns linux friendly! :)
 
Last edited by a moderator:
Im just copying what everyone else is doing atm, run the game with a script. Something like this...

Code:
/mnt/sd/GAME_PATH/GAME_EXE

cd /usr/gp2x
./gp2xmenu

Just remember to keep the carrier returns linux friendly! :)

Cool - that works a treat. I was getting bored of waiting for my Gp2x to reboot after every time I ran my program :)
(I was just being dozy, and hadn't noticed that everyone else was launching via scripts :p )

Thanks a bunch.
 
Last edited by a moderator:
Back
Top