Open2x Makefile


motorollin

Member
Joined
Jul 31, 2007
Messages
163
I have never set up a dev environment in Linux before. In Dev-C++ under Windows it's all done for you. I'm trying to modify a Dev-C++ makefile to get my game to compile and run under Linux. Here's what I've done so far:
CODE

# Project: GridWars2x
# Makefile created by Dev-C++ 4.9.9.2

CPP = g++
CC = gcc
OBJ = linux/main.o linux/spriteclasses.o
LINKOBJ = linux/main.o linux/spriteclasses.o
LIBS = -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont
INCS = -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/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL_mixer
CXXINCS = -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1/backward -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1 -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/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL_mixer
BIN = gridwars2x
CXXFLAGS = $(CXXINCS) -DLINUX
CFLAGS = $(INCS) -D_REENTRANT -DLINUX
RM = rm -f
MKDIR = mkdir -p

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

all: all-before gridwars2x all-after

all-before:
$(MKDIR) "linux"


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

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $@ $(LIBS)

linux/main.o: main.c
$(CPP) -c main.c -o linux/main.o $(CXXFLAGS)

linux/spriteclasses.o: spriteclasses.cpp
$(CPP) -c spriteclasses.cpp -o linux/spriteclasses.o $(CXXFLAGS)



When I do `make -f Makefile.linux` I get errors like "/usr/bin/ld: skipping incompatible /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib/libSDL_mixer.so when searching for -lSDL_mixer" and "/usr/bin/ld: skipping incompatible /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib/libSDL_mixer.so when searching for -lSDL_mixer". I get similar errors for SDL_image.
 
CC = gcc

Chances are you're using the standard i386 gcc not the gp2x arm version. Make sure the path to gcc and it's name are correct. Same goes for things like g++ and ld.
 
woogal said:
CC = gcc

Chances are you're using the standard i386 gcc not the gp2x arm version. Make sure the path to gcc and it's name are correct. Same goes for things like g++ and ld.
Oh right, so gcc and g++ have to be the arm versions even if I'm compiling the app to run in Linux not on the GP2X?
 
Last edited by a moderator:
What exactly are you trying to do? You're using i386 gcc, but gp2x arm compiled libs (/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib). If you want a gp2x executable you need to use an arm version of gcc, but if you want an i386 linux executable you need i386 libs.
 
I am trying to set up Open2x to compile my game either for Linux or for the GP2X, just like I would have done in Dev-C++ under Windows. I assumed since the libraries (SDL etc) were header files they were source, so would be platform independent. Is that not the case?
 
do you have OPEN2X set in your environment + path?

what happens if you type

arm-open2x-linux-gcc -v

if you dont get any output its not setup right in your path.


CC = arm-open2x-linux-gcc
CPP = arm-open2x-linux-g++

add a -static to your LIBS line


I use a different build system from make so I cant much help you (I hate makefiles).
 
motorollin said:
I assumed since the libraries (SDL etc) were header files they were source, so would be platform independent. Is that not the case?
Yes, but you are linking with arm libraries, not just headers. Libraries are platform specific.
 
Last edited by a moderator:
*Right* let me get this straight.

- Makefile for running in Linux: GCC/G++ points to i386 compilers, include vars point to folders containing both headers and i386 binary versions of the libraries

- Makefile for running in GP2X: GCC/G++ points to arm compilers, include vars point to folders containing both headers and arm binary versions of the libraries

Correct?
 
Ok since I've got the Open2x toolchain installed, I figure I've got binaries for the libraries I need along with the headers and the arm compilers. So here's the GP2X makefile I've knocked together:

CODE

# Project: GridWars2x
# Makefile created by Dev-C++ 4.9.9.2

CPP = /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/bin/arm-open2x-linux-g++
CC = /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/bin/arm-open2x-linux-gcc
OBJ = gp2x/main.o gp2x/spriteclasses.o
LINKOBJ = gp2x/main.o gp2x/spriteclasses.o
LIBS = -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/include -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont
INCS = -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
CXXINCS = -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1/backward -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1 -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
BIN = GridWars2x.gpe
CXXFLAGS = $(CXXINCS) -DGP2X
CFLAGS = $(INCS) -D_REENTRANT -DGP2X
RM = rm -f
MKDIR = mkdir -p

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

all: all-before GridWars2x.gpe all-after

all-before:
$(MKDIR) "gp2x"


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

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $@ $(LIBS)

gp2x/main.o: main.c
$(CPP) -c main.c -o gp2x/main.o $(CXXFLAGS)

gp2x/spriteclasses.o: spriteclasses.cpp
$(CPP) -c spriteclasses.cpp -o gp2x/spriteclasses.o $(CXXFLAGS)


When I do `make -f Makefile.gp2x` I get "ld: cannot find -lSDL_image". Losing patience with this now! :angry:
 
Have you checked that the lib files exist in the folder that you have specified?
 
Yes, /opt/open2x/gcc-4.1.1-glibc-2.3.6/lib contains lots of libraries including lib_SDL_image. However, /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/lib contains hardly anything, so I'm wondering if the ones in /opt/open2x/gcc-4.1.1-glibc-2.3.6/include are the correct ones, or whether I need to compile arm version and put them in /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/lib?
 
-L/opt/open2x/gcc-4.1.1-glibc-2.3.6/include is telling the linker to look for libs in the include directory. This should be pointing to a libs directory instead.
 
Ok I changed that line to "LIBS = -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont" but I'm still getting the same error.

The directory specified for the libs contains lots of files including libSDL_image.so, which is a symlink to libSDL_image-1.2.so.0.1.3, which is reported as "ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped". So I really don't get why this isn't working!
 
I've rewritten it somewhat, but cant obviously test it.

make sure /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/bin is in the PATH environment var!!!

it probably wont work right off the bat.
(make sure the makefile is in the same directory as all the .c/.cpp files)

CODE

OPEN2X = /opt/open2x/gcc-4.1.1-glibc-2.3.6

CPP = arm-open2x-linux-g++
CC = arm-open2x-linux-gcc
OBJ = main.o spriteclasses.o
LIBS = -L$(OPEN2X)/lib -L$(OPEN2X)/arm-open2x-linux/lib -static -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont
INCS = -I$(OPEN2X)/include -I$(OPEN2X)/include/SDL
CXXINCS = -I$(OPEN2X)/include/c++/4.1.1/backward -I$(OPEN2X)/include/c++/4.1.1 $(INCS)
CXXFLAGS = $(CXXINCS) -DGP2X
CFLAGS = $(INCS) -D_REENTRANT -DGP2X

all: GridWars2x.gpe

clean:
rm -rf GridWars2x.gpe $(OBJ)

GridWars2x.gpe: $(OBJ)
$(CPP) $(OBJ) -o $@ $(LIBS)


.c.o: .autodepend
$(CC) -c $(CFLAGS) $*.c

.cc.o:
$(CC) -c $(CXXFLAGS) $*.cc

.cpp.o:
$(CC) -c $(CXXFLAGS) $*.cpp



Since you asked me what I use, my buildsystem is 'rant' which is like makefiles using Ruby (not to be confused with Ant). Its way more flexible than Makefiles (since its backed by a full programming language).

It really only comes into play when your build process gets big. Fishguts compiles lots of tools and game data and stuff as well as doing multiplatform builds between the gp2x, psp and pc etc.

Make should be perfectly fine when your just compile a few files.



motorollin said:
Ok I changed that line to "LIBS = -L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont" but I'm still getting the same error.

The directory specified for the libs contains lots of files including libSDL_image.so, which is a symlink to libSDL_image-1.2.so.0.1.3, which is reported as "ELF 32-bit LSB shared object, ARM, version 1 (ARM), not stripped". So I really don't get why this isn't working!
check in your libs directory for a SDL_image.a file and remember to compile as with -static in your LIBS line.
 
Last edited by a moderator:
Think I've got a bit further now. Now I'm getting lots of errors like the following:

In file included from /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1/memory:57,
from /opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1/string:47,
from main.c:5:
/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/c++/4.1.1/bits/stl_uninitialized.h:66: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'std'


Looks like it's having problems including the standard C++ libs. I'm about to lose my tempter and go back to Windows, and my game will just have to do without MOD playback :angry:
 
Squidge said:
C++? Try G++ instead of GCC in that case.
Ok I changed the Makefile to use g++ and it gets further now, but I get lots of errors from the SDL libraries, things like "undefined reference to `pthread_cancel'"
 
Last edited by a moderator:
YakumoFuji said:
add -lpthread to your LIBS line
Right! Getting somewhere now. The game compiles without any errors, just a couple of warnings about converting from int to double, but they came up in Dev-C++ too and didn't affect the running of the game.

However, when I actually run the game on the GP2X it quits back to the menu if I run from the standard GP2X game launcher, or hangs saying "Launching Gridwars2x" if I run it from Gmenu2x. This is frustrating. It's taken all day to get to this stage and I feel like I'm so close!
 
Last edited by a moderator:
Back
Top