Compiling Hellopixel.c


deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
Hi,

I try to start developing with compiling hellopixel.c - but that isn't that easy.

I'm working with a linux-live-system (grml.org) and try to setup the environment to use the toolchain from torpor (includes SDL).

Fist I untared the toolchain to /toolchain, made a directory /opt/openwiz (mkdir -p /opt/openwiz/) and a link to toolchain (ln -s /toolchain /opt/openwiz/toolchain).
Then I put hellopixel.c to /opt and changed to /opt (cd /opt).

After this I tried to compile hellopixel.c with:
/opt/openwiz/toolchain/arm-openwiz-linux-gnu/bin/arm-openwiz-linux-gnu-gcc -I /opt/openwiz/toolchain/arm-openwiz-linux-gnu/include/SDL -lSDL hellopixel.c -o hellopixel.gpe

But finally I got linker-errors regarding libSDL: cannot find -lSDL.
Trying to expand the PATH doesn't improve much. One of the further errors was: libiconv.so.2 needed libSDL.so (with undefined references).

Now I don't know what to try. Before doing it with a makefile I would like to understand it with a compile command.

Thanks for any help/hint.
deetee
 

glezmen

Member
Joined
Aug 25, 2009
Messages
297
have a look at the Caanoo Makefile of my game: cooldown

don't suffer with plain command line switches, the makefile does the same without having to type for minutes
 

deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
Hi!

Thanks for your hint.

I tried your Makefile (without modifications) - but after starting with "make -f Makefile" I got this error(s):

Package sdl was not found in the pkg-config search path.
Perhaps you should add the directory containing 'sdl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sdl' found
/opt/arm-openwiz-linux-gnu/bin/arm-openwiz-linux-gnu-c++ -I/opt/arm-openwiz-linux-gnu/include/ -I/opt/arm-openwiz-linux-gnu/include/SDL -DWIZ -DNOLOG -fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -O2 src/*cpp -o cooldown-wiz -L/opt/arm-openwiz-linux-gnu/lib -Wl,-rpath,. -lm -lz -lpng -liconv -lfreetype -lmad -lvorbisidec -lSDL -lSDL_ttf -lSDL_mixer -lSDL_image
arm-openwiz-linux-gnu-c++: src/*cpp No such file or directory
make: *** [build] Error 1

As I'm not really a specialist of Linux and Makefiles (I only wanted to write a small program for my wiz) I see, that the compiler couldn't find the SDL-package (which is in /opt/arm.../include/SDL/). In addition the compiler has problems with src/*cpp (whatever this means).

How can I modify your Makefile or set environment variables?

Thanks for any help.
deetee
 

glezmen

Member
Joined
Aug 25, 2009
Messages
297
the problem is that you have no SDL installed in your system, so pkg-config can't find it

iyou can change the makefile to use a fixed LIBS/INCS variable by providing the full path to your toolkit

hm, i just checked the Makefile, and pkg-config is not called (unless you uncommented it):

oops, you're talking about WIZ, not Caanoo.. but the way to go is the same

the src/*.cpp is the path for your source files. if they are in a different directory or in the current one, modify the path
so if your source files are in the same directory as the Makefile, you can simply use *.cpp (or *.c for C source)

you can also remove the 'move' target, so your makefile will look something like this:


Code:
SDKDIR    = $(HOME)/GPH_SDK
ARMDIR    = $(SDKDIR)/tools/gcc-4.2.4-glibc-2.7-eabi
CPP       = $(ARMDIR)/bin/arm-gph-linux-gnueabi-g++
LIBS      = -L$(SDKDIR)/lib/target -L$(DGEDIR)/lib/target -L$(ARMDIR)/lib -Wl,-rpath,. -lm -lz -lpng -lfreetype -lsmpeg -lmad -lvorbisidec -logg -lvorbis -lvorbisfile -lSDL -lSDL_ttf -lSDL_mixer -lSDL_image
INCS      = -I$(SDKDIR)/include -I$(DGEDIR)/include -I$(DGEDIR)/include/SDL -I$(ARMDIR)/include/ -I$(ARMDIR)/include/SDL# $(shell pkg-config --cflags sdl)
CXXFLAGS  = $(INCS) $(DEFINES) -fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -O2
OUTPUT    = hellopixel-caanoo

all:
	$(CPP) $(CXXFLAGS) *.cpp *.c -o $(OUTPUT) $(LIBS)

change the paths/names of the compiler executables (SDKDIR, ARMDIR, CPP, LIBS, INCS) to the path where you installed them
 

deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
Hello glezmen!

Thanks for your (very) fast resonse - I think I'm a little bit closer to success now.

After modyfied your makefile to:

ARMDIR = /opt/arm-openwiz-linux-gnu
CPP = $(ARMDIR)/bin/arm-openwiz-linux-gnu-c++
LIBS = -L$(ARMDIR)/lib -L$(ARMDIR)/libexec -Wl,-rpath,. -lm -lz -lpng -lfreetype -lmad -lvorbisidec -logg -lvorbis -lvorbisfile -lSDL -lSDL_ttf -lSDL_mixer -lSDL_image
INCS = -I$(ARMDIR)/include -I$(ARMDIR)/include/SDL
CXXFLAGS = $(INCS) -fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -O2
OUTPUT = hellopixel

all:
$(CPP) $(CXXFLAGS) *.c -o $(OUTPUT) $(LIBS)

I got warnings and errors regarding the SDL-library:
... warning ... libiconv.so.2 needed by ... libSDL.so ... not found
... libSDL.so ... undefined reference to libiconv ... libiconv_close ... libiconv_open
ld returned 1 exit status

Any further improvements/hints/tipps?

Thanks in advance
deetee
 

glezmen

Member
Joined
Aug 25, 2009
Messages
297
that's much better :) now you will need the missing library (libiconv.so.2)
does it exist somewhere in the toolchain dir (it should)?
if you can't find it anywhere, you can download a game what uses it (like Cooldown WIZ port) and copy the libiconv.so.2 file to the toolchain's lib directory

(but if you really miss that file, maybe you have an uncompleted/old version of the toolchain)
 

deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
Hello glezmen!

There is a libiconv.so.2 in my [torpors] toolchain under:
/opt/arm-openwiz-linux-gnu/lib/

... but this path seems to be set in the LIBS-section of my makefile :-[

what now?

TIA
deetee
 

deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
glezmen - you are great - many, many thanks

It compiled without any comments - and got an ELF-file "hellopixel".

But then I copied it as "hellopixel.gpe" to my wiz and started it with the launcher - and it finally hung up at the "Loading"-screen.

Starting in termula it says:
Error while loading shared libraries: libiconv.so.2 ... no such file.

What do I have to do now? - copy libiconv.so.2 from my toolchain to WIZ/..SD../lib ?

TIA
deetee
 

glezmen

Member
Joined
Aug 25, 2009
Messages
297
the problem is that libiconv is not installed on the WIZ
to be sure your program will run, copy the missing libraries in the directory where hellopixel.gpe is, and launch it this way:

LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./hellopixel

this way the libraries will be searched in the current directory first, and if they are not there, in the default directories
 

deetee

Still Fresh
Joined
Jul 28, 2010
Messages
19
Location
Vienna, Austria
Success!! - first milestone (to my first WIZ-program) reached

I made a file "start.gpe" which executes your code and copied libconv, libvorbis and libvorbisfile to my wiz.
Launching start.gpe shows me a mouse cursor and my hard expected pixel.

But I wonder how other programs can do it without those libs?

Thanks to you glezmen ... and for sharing parts of your huge knowledge base with me
 

glezmen

Member
Joined
Aug 25, 2009
Messages
297
i'm glad I can help, hopefully we will have great games by you soon :)
and my knowledge is very far from being huge, most of it is from the gp32x forums

if you don't want to play OGG files, the vorbis libs are not needed (after you remove them from the LIBS variable)
and you can also omit other libs if you use an SDL version which doesn't require them

and on Caanoo, you don't need them, all the libs I needed were installed on it by default
 
Top