GP2X Sdl/sdl_draw Hello World For Gp2x


TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
I've been toying SDL development, and things are looking good on my Linux system. I've got a first few programs of the "Hello World" variety, using SDL and SDL_draw. I'm looking ahead to SDL development for the Pandora next year.

I'd like to attempt to bring these programs over to my GP2X F200, to ensure I know what I'm doing and that I can continue development on LInux. Can I verify that I want to install the Open2X toolchain (http://wiki.gp2x.org/wiki/Installing_the_Open2x_toolchain), and compile my program with this or a similar command on my Linux box?

/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-g++ -lSDL -lSDL_draw SDLTest.cpp -o SDLTest

Sadly at the moment I'm getting a "version `GLIBC_2.4' not found" error, but I know this isn't a open2x or g++ issue. I also know the last time I tried to upgrade to GLIBC 2.4 on my Slackware 11.0 system I lost several hours of my life and suffered a small heart attack before mostly reverting back to GLIBC2.3. Time to move development to a real operating system and plot to upgrade my server...

(actually, that's odd.. the toolchain says it's for glib2.3.6... It's possible I've fried my system more than I feared when I attempted the 2.4 upgrade).

I also have some concerns that SDL_draw (primitive graphics library) will actually work without open2x specific libraries.. but here I show my SDL noobishness. Should I be able to get SDL_draw working on the GP2X? Can I just compile against my existing libraries or does SDL_draw need to be compiled against the arm processor?

Thanks in advance for your replies and patience. Any hints or pointers you can provide would be greatly appreciated.
 
OK, SDL_draw aside for a moment.

I've moved to another machine that doesn't' have the GLIBC issue. I'm trying to compile the simplest of SDL programs: LazyFoo's Tutorial 1, which basically initializes SDL and exits.

CODE
#include "SDL/SDL.h"

int main( int argc, char* args[] ) {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}


Works great in Ubuntu compiled for x86. I can also compile this for arm using modified compile in another thread:

/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-g++ -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -L /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lSDL BasicSDL.cpp -o BasicSDL.gpe

No errors... not tested yet though.

However if I throw a -static in the mix, I get errors...

CODE
/tmp/cczG8Cpn.o: In function `main':
BasicSDL.cpp:(.text+0x1c): undefined reference to `SDL_Init'
BasicSDL.cpp:(.text+0x20): undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status


If I had to guess it can't compile staticly against the open2x libraries. Do I need to have a working arm compile of SDL to staticly compile?

I also have questions about compiling SDL_draw against the open2x toolkit, but I'll ask those later.. one problem at a time...
 
After the word static you usually list the libs you want to statically link with like

-static -lSDLmain -lSDL_mixer -lSDL_svg -lSDL_ttf -lSDL_image -lSDL_gfx -ljpeg -lpng -lmikmod -lreadline -lsmpeg -logg -lvorbis -lvorbisidec -lvorbisenc -lvorbisfile -lxml2 `../bin/sdl-config --libs` -lz

the order is important, with static you not only link a library but the libraries it uses.
 
OK, an update: I can verify the non-staticly compiled SDL gpe is working properly on my GP2X. I even have Lazy Foo's tutorial2 (modified for gp2x screensize) displaying a Hello World graphic.

Back to static compile:

Hmm... I seem to get the same error even if I put static in the correct place. ala:

/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-g++ -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -L /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -static -l SDL BasicSDL.cpp -o BasicSDL.gpe

Though there's no reason why I should need to compile SDL staticly into my app.

Maybe I should move on to my next question. How would I compile SDL_draw libs for arm?

I'm guessing I'll need to pass several parameters to ./configure... I did manage to change CC, but I wasn't even close to getting the compile working.

Thanks for your information and your patience.

EDIT: I'm obviously doing something stupid because I get the same errors compiling for x86:

CODE
tgb@tikal:~/SDLTest$ g++ -lSDL BasicSDL.cpp
(compiles fine)
tgb@tikal:~/SDLTest$ g++ -static -lSDL BasicSDL.cpp
/tmp/ccy7oYZm.o: In function `main':
BasicSDL.cpp:(.text+0x19): undefined reference to `SDL_Init'
BasicSDL.cpp:(.text+0x1e): undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status
 
Trevor Bradley said:
CODE
tgb@tikal:~/SDLTest$ g++ -lSDL BasicSDL.cpp
(compiles fine)
tgb@tikal:~/SDLTest$ g++ -static -lSDL BasicSDL.cpp
/tmp/ccy7oYZm.o: In function `main':
BasicSDL.cpp:(.text+0x19): undefined reference to `SDL_Init'
BasicSDL.cpp:(.text+0x1e): undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status
That should actually be "g++ -static BasicSDL.cpp -lSDL -lpthread -o BasicSDL.gpe" as with static linking, you have to ensure that everything is in order of reference, IE: your BasicSDL.cpp calls on SDL_Init/SDL_Quit which are in SDL. Your version of SDL was probably compiled with posix threads so we add the pthread library. Doing this under Ubuntu, however, is lots of fun as Ubuntu's SDL has a great mass of crap compiled in as well and the `sdl-config --cflags --static-libs` trick doesn't seem to pull them all in ;) so be warned that it may throw up a huge amount of undefined resources if you try it on Ubuntu.

Also, with the Open2X toolchain you have to statically link for it to work on the GP2X due to glibc issues. The GP2Xs default firmware uses an older one, whereas the Open2X firmware and toolchain uses a newer version.
 
Last edited by a moderator:
OK Stuckie, thanks, this appears to work for me:

/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-g++ -static BasicSDL.cpp -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -I /usr/include/ -L /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lSDL -lpthread

Which generates a nice 950K file instead of a 7K file.

And as you said, it *doesn't* work for x86 Ubuntu... but that's perfectly fine with me.

OK, next step then (and almost there!). How would I compile SDL_draw for arm?

Thanks everyone for your help so far... It's greatly appreciated.
 
This is a very quick and dirty hacked up Makefile using lots of ripped stuff from the Open2X library Makefiles.

I can only get it to build a static library for some reason, as it's complaining that libtool doesn't support shared libraries ( meaning I've probably missed something, hehe ) but.. should get you started at least, since you'll need to statically link for the GP2X anyway ;)

CODE

OPEN2X=/opt/open2x/gcc-4.1.1-glibc-2.3.6
HOST=arm-open2x-linux
TARGET=arm-open2x-linux
BUILD=`uname -m`

FLAGS += CC='$(OPEN2X)/bin/$(HOST)-gcc'
FLAGS += CXX='$(OPEN2X)/bin/$(HOST)-g++'
FLAGS += AR='$(OPEN2X)/bin/$(HOST)-ar'
FLAGS += STRIP='$(OPEN2X)/bin/$(HOST)-strip'
FLAGS += RANLIB='$(OPEN2X)/bin/$(HOST)-ranlib'

FLAGS += CFLAGS='-O3 -ffast-math -fomit-frame-pointer -mcpu=arm920t -DARM -D_ARM_ASSEM_ -I$(OPEN2X)/include -I$(OPEN2X)/include/libxml2 -I$(OPEN2X)/include/SDL'
FLAGS += LDFLAGS='-L$(OPEN2X)/lib'
FLAGS += PKG_CONFIG='$(OPEN2X)/bin/pkg-config'

sdl_draw:
@-echo "Build SDL_draw"
(rm -rf config.cache; \
$(FLAGS) ./configure --prefix=$(OPEN2X)\
--target=$(TARGET)\
--host=$(HOST)\
--build=$(BUILD)\
--enable-shared\
--enable-static\
--with-sdl-prefix=$(OPEN2X)\
)
$(FLAGS) make
$(FLAGS) make install
$(FLAGS) make clean




I put that into a "buildme.mk" file, then did "make -f buildme.mk" in the folder I extracted SDL_draw to.
It built and seemed to stick things in the right place, but I haven't tested it yet as it's 1:22am and I possibly should get some sleep ;)

Hope that helps though!
 
Awesome Stuckie! I'll give this a try very soon. (Cooking supper right now, sauces burn too easily if you try to compile and cook at the same time)

Once I get this working I can move off the GP2X and focus on C and SDL programming on Linux, knowing I can port over later. (Pity me for owning an F200...)
 
OK, I had some issues until I realized that makefiles are dependent on positions of Tabs, and I think the forum is eating tabs and converting them to spaces.

But even with that fixed I seem to get "*** commands commence before first target. Stop." errors. They go away if I remove the three tabbed "$(FLAGS) make" commands. I don't think make likes "make" to be inside a makefile. Google searching comes up with "A Makefile is not a script" and the like.

I tried running configure manually, but I gave up about halfway through when I feared that I'd get the export variables wrong... best to fix the Makefile rather than write an equally long and complex shell script.

Sorry this is turning into a Makefile howto. I know enough to fiddle with the things and set parameters, but otherwise I'm used to ant and other things Java... Time to learn, I'll need it for my project anyways...

Thanks again for your help.
 
Trevor Bradley said:
OK, I had some issues until I realized that makefiles are dependent on positions of Tabs, and I think the forum is eating tabs and converting them to spaces.
Agh, I apologise for that, I never checked to make sure the tabs stayed correct.
I had the same "commands commence before first target" problem, and yea it is a tab issue..

CODE

sdl_draw:
<tab>@-echo "Build SDL_draw"
<tab>(rm -rf config.cache; \
<tab><tab>$(FLAGS) ./configure --prefix=$(OPEN2X)\
<tab><tab><tab><tab>--target=$(TARGET)\
<tab><tab><tab><tab>--host=$(HOST)\
<tab><tab><tab><tab>--build=$(BUILD)\
<tab><tab><tab><tab>--enable-shared\
<tab><tab><tab><tab>--enable-static\
<tab><tab><tab><tab>--with-sdl-prefix=$(OPEN2X)\
<tab>)
<tab>$(FLAGS) make
<tab>$(FLAGS) make install
<tab>$(FLAGS) make clean



Basically the forum is converting a tab to four spaces, so if you re-tab the above like that, it should start compiling.. if not, I'll upload the actual file somewhere and ensure it still works when I re-download it ;)

Sorry about that! it was a bit late and I really should've checked :\
 
Last edited by a moderator:
*Bows before the Master of the Makefile*

It compiled nicely, and my SDL_draw test app also compiled nicely with the -static flag and the libraries carefully placed in the right order... (app, then SDL_draw, then SDL, then pthread). For reference (because I've found these threads pretty useful), that's:

/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/arm-open2x-linux-g++ -static SDLGrow.cpp -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include -I /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -I /usr/include/ -L /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -l SDL_draw -lSDL -lpthread

(EDIT: A minor note here... the install of SDL_draw didn't seem to copy SDL_draw.h to /opt/open2x/gcc-4.1.1-glibc-2.3.6/include, which is why "-I /usr/include" is in there. If I copy the file manually and remove /usr/include it works fine too)

My SDL_draw test app is running nicely on my GP2X right now. Now I have trivial things like joystick input and mouse cursors to deal with, but that's well documented on the wiki.

Thank you very much Stuckie. Your help has been greatly appreciated. Better knowledge of Open2X makefile is going to help me when my project gains some steam.

One last question of clarification. I did manage to compile an SDL test that dynamically linked to the SDL libraries that ran just fine on my GP2X, though it was a primitive test. I read previously here that GP2X binaries should be compiled staticly because of Open2X. Ideally I'd like to just compile only SDL_draw staticly and use the SDL libraries. (A) Is it possible to compile staticly against SDL_draw but dynamically against SDL and pthrerad, and if so how? And (B) Is this a really dumb idea considering I'm using the Open2X toolchain?
 
Ummm.... you need to link statically for the GPH firmware, not for Open2x. Yes, you can mix shared and static libs, but there is absolutely no point if you want to run on the GPH firmware. If you wanted to run the binary only on Open2x, that is a different matter entirely and it then becomes useful to use the up to date shared libs in the firmware but static link anything obscure (like SDL_draw) which you are using.

Is there any particular reason why you are using SDL_draw? SDL_gfx can do all the same and more, and is included with pretty much every toolchain for the GP2X.
 
Orkie said:
Ummm.... you need to link statically for the GPH firmware, not for Open2x. Yes, you can mix shared and static libs, but there is absolutely no point if you want to run on the GPH firmware. If you wanted to run the binary only on Open2x, that is a different matter entirely and it then becomes useful to use the up to date shared libs in the firmware but static link anything obscure (like SDL_draw) which you are using.
As I said, I managed to run a basic, dynamically linked Open2X binary on GPH firmware. But as I said, it was about 4 lines long, simply loaded a bitmap to the screen, and likely worked by sheer luck.

Orkie said:
Is there any particular reason why you are using SDL_draw? SDL_gfx can do all the same and more, and is included with pretty much every toolchain for the GP2X.
Because I'm a noob and wasn't aware SDL_gfx existed?

*headdesk*

That's what I get for looking almost exclusively at Lazy Foo and not seeing what I'm looking for. I'll transition over to SDL_gfx. Can you recommend a resource that would help me learn about other SDL packages?

(Sadly, still no arbitrary ellipse function in SDL_gfx (not fixed to the X or Y axis)... I'm going to have to code that one myself. Off to work!)
 
Last edited by a moderator:
Orkie said:
Is there any particular reason why you are using SDL_draw? SDL_gfx can do all the same and more, and is included with pretty much every toolchain for the GP2X.
I was partially wondering that myself, but I kinda thought perhaps SDL_draw had something unique to it that was needed ( the ellipse thing seems to be one, for example, hehe ) so just tried to help get it working :)

If anything, it was a nice little diversion while I figure out the next bug that's screwing my SGZEngine project up, even if I did somewhat plagiarize Orkie's Makefiles somewhat :D
 
Last edited by a moderator:
Well, honestly, I enjoyed the help getting my compiler set up. And this is extremely useful for when I start making my own makefile.

As for the ellipse, SDL_draw doesn't have arbitrary ellipses either. :| They're somewhat hard to draw and only useful for freaks like me trying to simulate orbital mechanics. ;)

Time for some SDL tuning though.. starting to hit flicker issues, but these have been discussed extensively in other threads and I can use those as a baseline.

Thanks everyone for your help!
 
Back
Top