Cross compiling on Linux for a win32 executable

Hi all,

I want to bore all my friends and family with the really cool things
I’ve been writing with SDL/OpenGL, meaning, I’d like to generate win32
executables on my Linux box.

After Googling, I followed the instructions given here:

http://www.libsdl.org/extras/win32/cross/README.txt

It took a little coaxing, but the gcc and binutils build went okay, and
appears to be installed correctly in /usr/local. I then downloaded the
scripts:

http://www.libsdl.org/extras/win32/cross/cross-configure.sh
http://www.libsdl.org/extras/win32/cross/cross-make.sh

Since I don’t know how to use autoconf (yet), the first script doesn’t
do me much good.

I really don’t know what I’m doing, since the only thing I’ve ever cross
compiled for was Lego Mindstorms, I naively copied cross-make.sh into
one of my projects and typed “sh cross-make.sh”. This is what I got:

colorgcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes
-Waggregate-return -Wpointer-arith -Wcast-qual -Wcast-align
-Wmissing-declarations -Wnested-externs -Wredundant-decls
-Wwrite-strings -Winline -Werror -g3 sdl-config --cflags -c -o init.o
init.c
as: unrecognized option `-Qy’
make: *** [init.o] Error 1

I’m beginning to see that the configure step was necessary for this,
since it appears to be using my “normal” makefile which is unsuited for
cross compiling for win32 (ie calling colorgcc rather than mingw32).

The error “as: unrecognized option `-Qy’” is a bit troubling; I hope it
doesn’t mean the cross compiling tools are broken (I didn’t see any
obvious error msgs when they installed). My as man page doesn’t list a
-Q option. Maybe my as needs updating.

I’ve hit a brick wall.

Is there a way to cross compile for a win32 application without needing
autotools?

Alternatively, is there a way to cross compile for a win32 without
needing to learn autotools? :wink:

Autotools are on my list todo, but there’s only so many things you can
learn at once. :slight_smile:

Thanks!
Pete

Peter Jay Salzman wrote:

I really don’t know what I’m doing, since the only thing I’ve ever cross
compiled for was Lego Mindstorms, I naively copied cross-make.sh into
one of my projects and typed “sh cross-make.sh”. This is what I got:

Doing exactly that works perfectly for me.

colorgcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes
-Waggregate-return -Wpointer-arith -Wcast-qual -Wcast-align
-Wmissing-declarations -Wnested-externs -Wredundant-decls
-Wwrite-strings -Winline -Werror -g3 sdl-config --cflags -c -o init.o
init.c
as: unrecognized option `-Qy’
make: *** [init.o] Error 1

I’m beginning to see that the configure step was necessary for this,
since it appears to be using my “normal” makefile which is unsuited for
cross compiling for win32 (ie calling colorgcc rather than mingw32).

Hmm, that colorgcc is surely causing trouble. You should make colorgcc
transparent, either by using the “alternatives” (see /etc/alternatives
if your distro has it) or by hand (/usr/bin/gcc becomes a link to colorgcc)

Also, I’m not sure a makefile should call “colorgcc”, that doesn’t sound
very portalbe :slight_smile:

Stephane

Hi Stephane,

Well, it got me closer, but still no cigar. I pared all the fancy
schmancy stuff from my Makefile. It’s bare bones now:

TARGET = 01-window
CFILES = $(wildcard *.c)
OFILES = $(patsubst %.c, %.o, $(CFILES))
CC = gcc
CPPFLAGS = sdl-config --cflags
LDLIBS = sdl-config --libs -lGL -lGLU -lm

all: $(TARGET)

$(TARGET): $(OFILES)
$(CC) -o $(TARGET) $(OFILES) $(LDLIBS)

.PHONY: clean

clean:
$(RM) $(TARGET) $(OFILES)

I’m now getting these errors:

In file included from init.c:1:
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1587: parse
error before “glAccum”
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1588: parse
error before “glActiveTextureARB”

… (about 484 more parse errors in gl.h)

In file included from init.c:5:
main.h:16: conflicting types for SDL_main' /usr/include/SDL/SDL_main.h:56: previous declaration ofSDL_main’
make: *** [init.o] Error 1

At least it’s trying. That’s progress. If you don’t see anything
obviously wrong, can you (or anybody?) email me a hello-world style
program with a makefile that cross compiles the program into a win32
executable?

Thanks!!!
PeteOn Sun 01 Aug 04, 5:32 PM, Stephane Marchesin <stephane.marchesin at wanadoo.fr> said: Peter Jay Salzman wrote:

I really don’t know what I’m doing, since the only thing I’ve ever cross
compiled for was Lego Mindstorms, I naively copied cross-make.sh into
one of my projects and typed “sh cross-make.sh”. This is what I got:

Doing exactly that works perfectly for me.

colorgcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes
-Waggregate-return -Wpointer-arith -Wcast-qual -Wcast-align
-Wmissing-declarations -Wnested-externs -Wredundant-decls
-Wwrite-strings -Winline -Werror -g3 sdl-config --cflags -c -o init.o
init.c
as: unrecognized option `-Qy’
make: *** [init.o] Error 1

I’m beginning to see that the configure step was necessary for this,
since it appears to be using my “normal” makefile which is unsuited for
cross compiling for win32 (ie calling colorgcc rather than mingw32).

Hmm, that colorgcc is surely causing trouble. You should make colorgcc
transparent, either by using the “alternatives” (see /etc/alternatives
if your distro has it) or by hand (/usr/bin/gcc becomes a link to colorgcc)

Also, I’m not sure a makefile should call “colorgcc”, that doesn’t sound
very portalbe :slight_smile:

Stephane

Peter Jay Salzman wrote:

I’m now getting these errors:

In file included from init.c:1:
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1587: parse
error before “glAccum”
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1588: parse
error before “glActiveTextureARB”

Looks like a sign that windows.h should be included, which in turns
means that you should use SDL_opengl.h which does that for you (for
portability reasons, it’s better to use SDL_opengl.h instead of GL/gl.h
directly)

… (about 484 more parse errors in gl.h)

In file included from init.c:5:
main.h:16: conflicting types for `SDL_main’

Why did you declare SDL_main ? You shouldn’t do that, this will (as you
see) interfer with the SDL headers.

/usr/include/SDL/SDL_main.h:56: previous declaration of `SDL_main’
make: *** [init.o] Error 1

At least it’s trying. That’s progress. If you don’t see anything
obviously wrong, can you (or anybody?) email me a hello-world style
program with a makefile that cross compiles the program into a win32
executable?

Or just get your own program to work, you’ll learn much more that way.

Stephane

This got rid of 486 parse errors! :slight_smile: Thanks!!! After switching all
my GL header includes for SDL_opengl.h, I got this new error message:

$ sh cross-make.sh
gcc sdl-config --cflags -c -o init.o init.c
gcc sdl-config --cflags -c -o main.o main.c
main.c:86: conflicting types for SDL_main' /usr/include/SDL/SDL_main.h:56: previous declaration ofSDL_main’
make: *** [main.o] Error 1

Line 86 of main.c is the start of main(). I’m not sure what made me do
this (desperation?), but I changed:

int main( void )

to

int main( int argc, char *argv[] )

and compiled again. This time, I got even farther!

$ sh cross-make.sh
gcc sdl-config --cflags -c -o init.o init.c
gcc sdl-config --cflags -c -o main.o main.c
gcc sdl-config --cflags -c -o video.o video.c
gcc sdl-config --cflags -c -o yerror.o yerror.c
gcc -o 01-window init.o main.o video.o yerror.o sdl-config --libs
-lGL -lGLU -lm
/usr/local/cross-tools/lib/gcc-lib/i386-mingw32msvc/3.2.3/…/…/…/…/i386-mingw32msvc/bin/ld:
cannot find -lSDL
make: *** [01-window] Error 1

Then it occured to me that the compiler can’t use libraries meant for
Linux compiling. I did a Google search and found:

SDL-devel-1.2.7-mingw32.tar.gz (Mingw32)

on the SDL download page. Guess I should’ve looked for this from the
start. Following the instructions in the “INSTALL” file, I installed it
with:

make cross

and it appeared to install correctly. Compiling went even farther:

$ sh cross-make.sh
gcc -o 01-window init.o main.o video.o yerror.o sdl-config --libs
-lGL -lGLU -lm
/usr/local/cross-tools/lib/gcc-lib/i386-mingw32msvc/3.2.3/…/…/…/…/i386-mingw32msvc/bin/ld:
cannot find -lpthread
make: *** [01-window] Error 1

I’m assumming that I either need a win32 port of pthread or sdl-config
–libs is giving the wrong option. I looked on the SDL download page
and couldn’t find anything relevent.

I feel like I’m very close now. Help? :slight_smile:

Thanks!
PeteOn Mon 02 Aug 04, 3:08 AM, Stephane Marchesin <stephane.marchesin at wanadoo.fr> said: Peter Jay Salzman wrote:

I’m now getting these errors:

In file included from init.c:1:
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1587: parse
error before “glAccum”
/usr/local/cross-tools/i386-mingw32msvc/include/GL/gl.h:1588: parse
error before “glActiveTextureARB”

Looks like a sign that windows.h should be included, which in turns
means that you should use SDL_opengl.h which does that for you (for
portability reasons, it’s better to use SDL_opengl.h instead of GL/gl.h
directly)

Which “sdl-config” are you running? (i.e., what’s its path?)
If it’s the Linux one, that could be causing probs (similarly to trying
to link the Win32 against Linux libs :^) )

I’m guessing it should be the one from that "SDL-devel-1.2.7-mingw32.tar.gz"
you had downloaded.

Good luck!

-bill!On Mon, Aug 02, 2004 at 05:55:29AM -0700, Peter Jay Salzman wrote:

$ sh cross-make.sh
gcc -o 01-window init.o main.o video.o yerror.o sdl-config --libs
-lGL -lGLU -lm
/usr/local/cross-tools/lib/gcc-lib/i386-mingw32msvc/3.2.3/…/…/…/…/i386-mingw32msvc/bin/ld:
cannot find -lpthread
make: *** [01-window] Error 1

I’m assumming that I either need a win32 port of pthread or sdl-config
–libs is giving the wrong option. I looked on the SDL download page
and couldn’t find anything relevent.

Bill Kendrick wrote:>On Mon, Aug 02, 2004 at 05:55:29AM -0700, Peter Jay Salzman wrote:

$ sh cross-make.sh
gcc -o 01-window init.o main.o video.o yerror.o sdl-config --libs
-lGL -lGLU -lm
/usr/local/cross-tools/lib/gcc-lib/i386-mingw32msvc/3.2.3/…/…/…/…/i386-mingw32msvc/bin/ld:
cannot find -lpthread
make: *** [01-window] Error 1

I’m assumming that I either need a win32 port of pthread or sdl-config
–libs is giving the wrong option. I looked on the SDL download page
and couldn’t find anything relevent.

Which “sdl-config” are you running? (i.e., what’s its path?)
If it’s the Linux one, that could be causing probs (similarly to trying
to link the Win32 against Linux libs :^) )

I’m guessing it should be the one from that "SDL-devel-1.2.7-mingw32.tar.gz"
you had downloaded.

To be even more specific : replace sdl-config --libs with
/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config --libs

Stephane