Compiler Frustration


Monkey

Still Fresh
Joined
Nov 11, 2005
Messages
13
Age
40
Location
Belfast, Norn Iron
Website
Visit site
I've been trying to compile a simple piece of code for my GP2x for the past few days and I've been going round and round in circles. I've followed all the instructions for setting everything up in the gp2x user guide, and it will compile the demo from the wiki but won't run my own code. This is my code:

Code:
#include "SDL.h"
#include "gpmain.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 16

int main(int argc, char *argv[]) {
     SDL_Surface *screen, *bmp;
     SDL_Rect targetarea;
     SDL_Init(SDL_INIT_VIDEO);
     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);

     bmp = SDL_LoadBMP("imagetest.bmp");

     targetarea.x = 1;
     targetarea.y = 1;
     targetarea.w = bmp->w;
     targetarea.h = bmp->h;
     
     SDL_BlitSurface(bmp, &targetarea, screen, &targetarea);

     SDL_Flip(screen);

     while(1);
}

Heres the 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 = test.gpe
SDLTEST_OBJS = main.o

all : $(SDLTEST_TARGET)

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

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

All I get doing this is a black screen with the cursor in the top left corner :huh:

I've thrown my files all up onto my uni webspace, here.

I'm pulling my hair out over this as I'm planning to do my final year uni project on it, but it won't even display a bitmap for me :blink:.
 
Ok... not sure why you need a main function prototype in gpmain.h :/

As far as I can tell, your program IS working (bmp is being loaded etc) but the code for drawing the bmp onto the screen is incorrect/non working. Plus it hangs like hell on exit not wanting to exit.

I be guessing that something is not being initialised properly.
 
Course, you're not doing error checking so you don't know where its failing :)

(does the image load?)

Could always log to see the decision path, after you've added error handling :p

jeff
 
Monkey posted on Dec 8 2005 at 03:31 AM said:
    bmp = SDL_LoadBMP("imagetest.bmp");
My guess is this should be changed to

bmp = SDL_LoadBMP("/mnt/sd/imagetest.bmp");
 
Last edited by a moderator:
I can't check any of this out just now as I'm at Uni, but here goes...

The code seems to be fine, but I'd change the blitting line to

Code:
SDL_BlitSurface(bmp, NULL, screen, &targetarea);
I don't think this would solve the problem itself, but give it a try anyway.
As for the makefile, you've set it up a bit different to what I'm used to, so here's a makefile to test out (substituting paths as appropriate):

Code:
# Project: Testing
# Makefile created by Dev-C++ 4.9.9.2

CPP  = arm-linux-g++.exe
CC   = arm-linux-gcc.exe
WINDRES = windres.exe
RES  =
OBJ  = main.o $(RES)
LINKOBJ  = main.o $(RES)
LIBS =  -L"C:/Dev-Cpp/devkitGP2X/lib" -lSDLmain -lSDL
INCS =  -I"C:/Dev-Cpp/devkitGP2X/include"
CXXINCS =  -I"C:/Dev-Cpp/devkitGP2X/lib/gcc/arm-linux/4.0.2/include"  -I"C:/Dev-Cpp/devkitGP2X/include/SDL"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2/backward"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2/arm-linux"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2"  -I"C:/Dev-Cpp/devkitGP2X/include"
BIN  = Testing.gpe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS)  
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Testing.gpe all-after


clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Testing.gpe" $(LIBS)

main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
Modify this makefile with your paths, give it a try, and let me know how it goes.


zaq121 posted on Dec 8 2005 at 08:16 PM said:
Monkey posted on Dec 8 2005 at 03:31 AM said:
bmp = SDL_LoadBMP("imagetest.bmp");
My guess is this should be changed to

bmp = SDL_LoadBMP("/mnt/sd/imagetest.bmp");
You don't have to give absolute paths to resources, and relative paths give better freedom as to where you want to put the files anyway. However, it also depends on how you execute the program in the first place. If executing directly, relative paths are fine, but if executing from a script, you must "cd" to the executable's directory before running the executable, or all relative paths will be broken.
 
Last edited by a moderator:
I tried out the demo file mentioned in the user guide and it works, so i'll be using its basis as a base from now on. I'm guessing that it was the load bmp code, as instead of loading it like this 'bmp = SDL_LoadBMP("test.bmp");' , where as I'm now loading like this 'SDL_Surface* bitmap = SDL_LoadBMP("test.bmp");' which works.

Thanks for the pointers guys.
 
Monkey posted on Dec 9 2005 at 01:50 PM said:
I tried out the demo file mentioned in the user guide and it works, so i'll be using its basis as a base from now on. I'm guessing that it was the load bmp code, as instead of loading it like this 'bmp = SDL_LoadBMP("test.bmp");' , where as I'm now loading like this 'SDL_Surface* bitmap = SDL_LoadBMP("test.bmp");' which works.

Thanks for the pointers guys.

Perhaps your variable bmp is not declared properly?
You could do:

Code:
SDL_Surface *bitmap;        /*declare the variable bmp */
bmp = SDL_LoadBMP("test.bmp");

It's personal preference of course, but I declare all my variables at the beginning of function rather than create them "as required" throughout the listing.
 
Last edited by a moderator:
Back
Top