Cross-Compiling

Hi!

I’m currently writing a breakout-style game, and I’d like to compile if
for Windows and Mac (I’m developing on Linux). I HAVE read throught the
archives and I’ve searched around, but there doesn’t seem to be any
concrete documentation on just exactly HOW you go about doing this. I did
run Ray Kelm’s cross.sh script to build a cross compiler. So now I have
/usr/local/cross-tools, what do I need to do to compile for windows? Or
Mac?

There really should be a HOWTO on this (hopefully there IS, and somebody
can point me to it). Thanks a lot!

Lyle

As a followup to my posting, I’ll give some specifics…

I’m trying to compile the “water” demo. I used cross-configure.sh, then
cross-make.sh but I get undefined references to SDL_Init(),
SDL_GetError(), SDL_Quit(), etc, etc.

The command used looks like this: gcc -g -O2 -I/usr/include/SDL
-D_REENTRANT -o water fixsin.o fps.o water.o -L/usr/lib
-Wl,-rpath,/usr/lib -lSDL -lpthread

I saw another post where somebody had a problem with the cross-configure
script using gcc as the $CC instead of i386-mingw32msvc-c++, but changing
it didn’t fix the errors for me.

If anyone can help me get past this little roadblock, I’d really
appreciate it.

Thanks,
LyleOn Sun, 19 Nov 2000, Lyle Hanson wrote:

Hi!

I’m currently writing a breakout-style game, and I’d like to compile if
for Windows and Mac (I’m developing on Linux). I HAVE read throught the
archives and I’ve searched around, but there doesn’t seem to be any
concrete documentation on just exactly HOW you go about doing this. I did
run Ray Kelm’s cross.sh script to build a cross compiler. So now I have
/usr/local/cross-tools, what do I need to do to compile for windows? Or
Mac?

There really should be a HOWTO on this (hopefully there IS, and somebody
can point me to it). Thanks a lot!

Lyle

Lyle Hanson wrote:

As a followup to my posting, I’ll give some specifics…

I’m trying to compile the “water” demo. I used cross-configure.sh, then
cross-make.sh but I get undefined references to SDL_Init(),
SDL_GetError(), SDL_Quit(), etc, etc.

The command used looks like this: gcc -g -O2 -I/usr/include/SDL
-D_REENTRANT -o water fixsin.o fps.o water.o -L/usr/lib
-Wl,-rpath,/usr/lib -lSDL -lpthread

I saw another post where somebody had a problem with the cross-configure
script using gcc as the $CC instead of i386-mingw32msvc-c++, but changing
it didn’t fix the errors for me.

If anyone can help me get past this little roadblock, I’d really
appreciate it.

Thanks,
Lyle

Hi!

I’m currently writing a breakout-style game, and I’d like to compile if
for Windows and Mac (I’m developing on Linux). I HAVE read throught the
archives and I’ve searched around, but there doesn’t seem to be any
concrete documentation on just exactly HOW you go about doing this. I did
run Ray Kelm’s cross.sh script to build a cross compiler. So now I have
/usr/local/cross-tools, what do I need to do to compile for windows? Or
Mac?

There really should be a HOWTO on this (hopefully there IS, and somebody
can point me to it). Thanks a lot!

Lyle

Unfortunately, in order to correctly support cross compiling, the
"configure.in" file for each project needs to have a few small changes.

All of the common SDL libraries have had these changes made (SDL,
SDL_image, SDL_ttf, SDL_net, etc) but many of the demos have not.

Attached is a patch, with instructions, that worked for me.

On a side note: Sam, if you could apply this to the original version
it might be nice :slight_smile:

Having the demos in CVS would be even nicer.

-Ray
-------------- next part --------------
Instructions:

  1. copy config.sub, config.guess, and autogen.sh from the SDL
    source code into the water-1.0 directory,
  2. From the water-1.0 directory, apply this patch using
    the following command: patch -p1 < water-1.0-cross-patch
  3. run ./autogen.sh to rebuild the configure script
  4. run cross-configure.sh and cross-make.sh to configure and
    build the “water” executable.

diff -u2 water-1.0/configure.in water-1.0-rhk/configure.in
— water-1.0/configure.in Tue Dec 21 01:18:59 1999
+++ water-1.0-rhk/configure.in Mon Nov 20 22:18:46 2000
@@ -5,4 +5,9 @@
AM_INIT_AUTOMAKE(water, 1.0)

+dnl Detect the canonical host and target build environment> On Sun, 19 Nov 2000, Lyle Hanson wrote:
+
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+
dnl Check for tools

Lyle Hanson wrote:

As a followup to my posting, I’ll give some specifics…

I’m trying to compile the “water” demo. I used cross-configure.sh, then
cross-make.sh but I get undefined references to SDL_Init(),
SDL_GetError(), SDL_Quit(), etc, etc.

The command used looks like this: gcc -g -O2 -I/usr/include/SDL
-D_REENTRANT -o water fixsin.o fps.o water.o -L/usr/lib
-Wl,-rpath,/usr/lib -lSDL -lpthread

I saw another post where somebody had a problem with the cross-configure
script using gcc as the $CC instead of i386-mingw32msvc-c++, but changing
it didn’t fix the errors for me.

If anyone can help me get past this little roadblock, I’d really
appreciate it.

Thanks,
Lyle

Hi!

I’m currently writing a breakout-style game, and I’d like to compile if
for Windows and Mac (I’m developing on Linux). I HAVE read throught the
archives and I’ve searched around, but there doesn’t seem to be any
concrete documentation on just exactly HOW you go about doing this. I did
run Ray Kelm’s cross.sh script to build a cross compiler. So now I have
/usr/local/cross-tools, what do I need to do to compile for windows? Or
Mac?

There really should be a HOWTO on this (hopefully there IS, and somebody
can point me to it). Thanks a lot!

Lyle

I should have thought of this before, but when you build and install
SDL for the cross compiler (download SDL, cross-configure and cross-make
it, then do “cross-make.sh install”) it will put a copy of sdl-config in
your cross compiler bin directory. If you don’t have thise sdl-config
file there, then compiling apps will just use the linux sdl-config file,
which has the “-lpthread” stuff. Look for this file to exist:

/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config

If it’s not, then install SDL for cross compiling as mentioned above.

-Ray> On Sun, 19 Nov 2000, Lyle Hanson wrote:

Thanks a lot Ray. Building SDL for cross-compilation and applying your
patch did the trick. Won’t be able to see if it runs on windows until I
get home, but it compiled fine.

While I’m on the topic, I wonder if somebody can answer a couple of other
questions I’ve been thinking about. What is the status of
cross-compilations for the Mac? Is anybody doing it? How?

Do I need to install and configure a copy of gcc for each architecture I
plan to support for the linux version? (i.e., ppc, alpha)B

When my game is finished, I’d like to distribute Linux, Windows, and
hopefully Mac versions. Is there an easy way to distribute source
packages without going in and creating, say, a linux source package that
uses gcc, and a windows package that has VC++ “project files” or
whatever? I’ve been trying to learn about how to use automake/autoconf,
but I guess those are just to allow easier distribution among Unices.

Any distro suggestions?

Thanks
Lyle> > As a followup to my posting, I’ll give some specifics…

I’m trying to compile the “water” demo. I used cross-configure.sh, then
cross-make.sh but I get undefined references to SDL_Init(),
SDL_GetError(), SDL_Quit(), etc, etc.

The command used looks like this: gcc -g -O2 -I/usr/include/SDL
-D_REENTRANT -o water fixsin.o fps.o water.o -L/usr/lib
-Wl,-rpath,/usr/lib -lSDL -lpthread

I saw another post where somebody had a problem with the cross-configure
script using gcc as the $CC instead of i386-mingw32msvc-c++, but changing
it didn’t fix the errors for me.

If anyone can help me get past this little roadblock, I’d really
appreciate it.

Thanks,
Lyle

I should have thought of this before, but when you build and install
SDL for the cross compiler (download SDL, cross-configure and cross-make
it, then do “cross-make.sh install”) it will put a copy of sdl-config in
your cross compiler bin directory. If you don’t have thise sdl-config
file there, then compiling apps will just use the linux sdl-config file,
which has the “-lpthread” stuff. Look for this file to exist:

/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config

If it’s not, then install SDL for cross compiling as mentioned above.

-Ray

While I’m on the topic, I wonder if somebody can answer a couple of other
questions I’ve been thinking about. What is the status of
cross-compilations for the Mac? Is anybody doing it? How?

I don’t know of anybody doing this. If somebody gets this working,
please let me know! :slight_smile:

-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

While I’m on the topic, I wonder if somebody can answer a couple of other
questions I’ve been thinking about. What is the status of
cross-compilations for the Mac? Is anybody doing it? How?

I don’t know of anybody doing this. If somebody gets this working,
please let me know! :slight_smile:

I have search for a considerable amount of time for something like this.
There are cross-compilers for the processors that Macs use. Someone needs to
make dummy MacOS libraries that the linker can use in place of the real ones.
Then when it is moved to the mac it should load the real libraries and work
fine. It just hasn;t been done…

    -- David Snopek

So here is the situation. I am running Ubuntu 8.04. I prefer to use Eclipse with
CDT extension for my IDE. My goal is to be able to compile C++ with SDL for
Linux and Windows target platforms. I am extremely new to SDL and moderately new
to C++. Unfortunately, I grew up as a web developer so I am not nearly as
skilled with compilers as I’d like to be. I can get a very simple C++ program
with SDL to compile and run in Linux. I cannot however get it to compile for
Windows. I have done a bit of cross-compiling for Windows, but it was so simple
no libraries were included. When I try to compile for Windows, the SDL.h file is
not found which makes me think I am not pointing to libraries properly. Does
anyone have experience with this or know where I could find a handy resource for
something such as this?

You better use the precompiled versions located on the SDL site. I wrote a
tutorial how to compile SDL 1.3 on windows here
http://wilku.ravenlord.ws/doku.php?id=wintutorial . Remember to switch the
SDL_config_win32 or sth like that for SDL_config;)

Good luck, mate.

2008/8/1 Shawn Sparks <shawn.sparks at 13throse.us>> So here is the situation. I am running Ubuntu 8.04. I prefer to use Eclipse

with
CDT extension for my IDE. My goal is to be able to compile C++ with SDL for
Linux and Windows target platforms. I am extremely new to SDL and
moderately new
to C++. Unfortunately, I grew up as a web developer so I am not nearly as
skilled with compilers as I’d like to be. I can get a very simple C++
program
with SDL to compile and run in Linux. I cannot however get it to compile
for
Windows. I have done a bit of cross-compiling for Windows, but it was so
simple
no libraries were included. When I try to compile for Windows, the SDL.h
file is
not found which makes me think I am not pointing to libraries properly.
Does
anyone have experience with this or know where I could find a handy
resource for
something such as this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


“For those about to code”
–Szymon “Wilku” Wilczek

I used to cross-compile SDL from Linux to both Linux and Windows using a
custom Makefile setup (i.e. redefine CC, CFLAGS, etc.) for each
architecture and xmingw installed in a local folder as compiler/toolchain.

Here is the archive of the compiler I used:
http://www.ferzkopp.net/Software/CrossMingw/

(It is probably hopelessly out of date, but may get you started.)

The configure.in file had stuff like this in it:

dnl Check for compilers
AC_LIBTOOL_WIN32_DLL
dnl Setup target flagsw
case “$target” in
--cygwin* | --mingw32*)
CFLAGS="$CFLAGS -DWIN32"
if test “$build” != “$target”; then # cross-compiling
ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
fi
;;
)
dnl nothing to do
;;
esac
dnl Figure out which math library to use and setup GL
case “$target” in
--cygwin
| --mingw32*)
MATHLIB="“
SYS_GL_LIBS=”-lopengl32"
;;
)
dnl nothing to do
;;
esac
dnl Figure out special libraries that are needed based on target
case “$target” in
--cygwin
| --mingw32*)
SPECIAL_LIBS="-lwsock32 -lwininet -lcomctl32"
;;
*)
SPECIAL_LIBS=""
;;
esac
AC_SUBST(MATHLIB)
AC_SUBST(SYS_GL_LIBS)
AC_SUBST(SPECIAL_LIBS)
LIBS="$LIBS $MATHLIB $SYS_GL_LIBS $SPECIAL_LIBS"

Shawn Sparks wrote:

So here is the situation. I am running Ubuntu 8.04. I prefer to use Eclipse with
CDT extension for my IDE. My goal is to be able to compile C++ with SDL for
Linux and Windows target platforms. I am extremely new to SDL and moderately new
to C++. Unfortunately, I grew up as a web developer so I am not nearly as
skilled with compilers as I’d like to be. I can get a very simple C++ program
with SDL to compile and run in Linux. I cannot however get it to compile for
Windows. I have done a bit of cross-compiling for Windows, but it was so simple
no libraries were included. When I try to compile for Windows, the SDL.h file is
not found which makes me think I am not pointing to libraries properly. Does
anyone have experience with this or know where I could find a handy resource for
something such as this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: aschiffler.vcf
Type: text/x-vcard
Size: 135 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080801/d1ae5615/attachment.vcf

For my projects, using regular makefiles (no autoconfig), I create a
basic template, and then modify them for each target OS. The results
looked like the following for the dynamic library. This approach isn’t
as generalizable as the autoconfig approach, but it may get you up and
running. Hope this helps,

John

#Makefile for linux using gcc
MAKEFILE = Makefile.unix
MKDP = makedepend

CC = g++
CFLAGS = -fPIC
LFLAGS = -shared
LIBS = -lGL -lGLU -lSDL -lSDL_image -lm
LIBDIR = /usr/lib

#Packages
SRCS = {Fill this in}

OBJS = $(SRCS:.cpp=.o)

MAIN = libXOR.so#

The following part of the makefile is generic; it can be used to

build any executable just by changing the definitions above and by

deleting dependencies appended to the file from ‘make depend’

all: $(MAIN)
cp -f $(MAIN) ./lib/$(MAIN)

install: $(SPECIAL)
cp -f ./lib/$(MAIN) $(LIBDIR)/$(MAIN)

$(MAIN): $(OBJS)
$(CC) $(LFLAGS) -o $(MAIN) $(OBJS) $(LIBS)

.cpp.o:
$(CC) $(CFLAGS) -o $@ -c $<

clean:
$(RM) $(OBJS) $(MAIN)

depend: $(SRCS)
$(MKDP) -f$(MAKEFILE) 2> /dev/null $(INCLUDES) $^

DO NOT DELETE THIS LINE – make depend needs it

-----For mingw, I changed the top portion to-----

#Makefile for windows using MinGW
MAKEFILE = Makefile.mingw

CFLAGS = -O3
CC = g++
LFLAGS = -shared

#Notice that libs dir does not specify the ending ''
LIBDIR = C:\Dev-Cpp\lib
LIBS = -L$(LIBDIR) -mwindows -lws2_32 -lmingw32 lib\SDL_image.dll
lib\libSDL.dll.a lib\libSDLmain.a -lopengl32 -lglu32 -lm

#Packages
SRCS = {Fill this in}
OBJS = $(SRCS:.cpp=.o)

MAIN = XOR.DLL

CP = COPY /Y

-----For OSX, I changed the top portion to-----

Makefile for the macintosh

MAKEFILE = Makefile.osx

Change the location of makedepend with this line, then comment out

the following definition.
#MKDP = /usr/X11R6/bin/makedepend
MKDP = makedepend
CC = g++
LFLAGS = -dynamiclib
LIBS = -L/sw/lib -framework OpenGL -framework SDL -framework SDL_mixer
-lSDL -framework SDL_image -lm

Notice that libdir does not specify the ending /

LIBDIR = /usr/local/lib

#Packages
SRCS = {Fill this in}
OBJS = $(SRCS:.cpp=.o)

MAIN = libXOR.so

.PHONY: FIRST depend clean

Since we are using an extra rule, we need to make sure that default

processing goes to the all target first.

FIRST: all

The install target will depend on SPECIAL, which means that

this target will acutally execute first.

Because we are just symlinking, that won’t cause any problems.

SPECIAL = libXOR.dylib

$(SPECIAL):
ln -fs $(LIBDIR)/$(MAIN) $(LIBDIR)/$(SPECIAL)

I used to cross-compile SDL from Linux to both Linux and Windows using a
custom Makefile setup (i.e. redefine CC, CFLAGS, etc.) for each architecture
and xmingw installed in a local folder as compiler/toolchain.

I used to cross-compile SDL from Linux to both Linux and Windows using a
custom Makefile setup (i.e. redefine CC, CFLAGS, etc.) for each architecture
and xmingw installed in a local folder as compiler/toolchain.

I went even more over-the-edge by cross-compiling for Linux, Windows
and Mac from Xcode using Cocotron’s patched cross-compiler generator
from cocotron.org (but I was unable to get Linux binaries to work,
unfortunately, but methinks it was a problem of the Cocotron runtime
rather than the cross-compiler – I was using ObjC in the code for all
versions).

  • ?On Fri, Aug 1, 2008 at 6:02 PM, Andreas Schiffler wrote:
    On Fri, Aug 1, 2008 at 6:02 PM, Andreas Schiffler wrote:

Shawn Sparks wrote:

So here is the situation. I am running Ubuntu 8.04. I prefer to use Eclipse with
CDT extension for my IDE. My goal is to be able to compile C++ with SDL for
Linux and Windows target platforms.

This response doesn’t specifically deal with cross-compiling, but in
case you’re trying to make sure your program works on older Gnu/Linux
systems, you will have some trouble if compiling on Ubuntu. Ubuntu’s
libraries have stack protection built in, and I’ve found that if you
build using Ubuntu’s libraries, your project will have dependencies on
GLIBC_2.4, whereas if you build on a Debian machine, you can make sure
it runs on systems which only have GLIBC_2.1.

I wrote about the problem on my blog:

http://gbgames.com/blog/2008/04/linux-game-development-frustrations-with-glibc_24-and-ubuntu/

If you don’t care about supporting older versions of distros, then this
issue isn’t a big concern.–
GBGames’ Blog, An Indie Game Developer’s Somewhat Interesting Thoughts:
http://www.gbgames.com/blog
Staff Reviewer for Game Tunnel, the Independent Underground:
http://www.gametunnel.com

If I understood you correctly what you want to do is to be able to compile
your code in both windows and linux. That is something actually not hard to
do specially if you stick with an IDE that run in multiple platforms. In my
case I use codeblocks and my code compiles out the box in windows and linux.
All I have to do is to open the workspace in windows and select the windows
build and it will build with not problems and then I go to linux and do the
same. In my case I’m building a shared library so the big thing is to take
care off dll exports under windows. I also use standard c++ so that also
helps. In linux it is compiled using gnu compiler and in windows using the
gnu tools port mingw.On Fri, Aug 1, 2008 at 10:15 AM, Shawn Sparks <shawn.sparks at 13throse.us>wrote:

So here is the situation. I am running Ubuntu 8.04. I prefer to use Eclipse
with
CDT extension for my IDE. My goal is to be able to compile C++ with SDL for
Linux and Windows target platforms. I am extremely new to SDL and
moderately new
to C++. Unfortunately, I grew up as a web developer so I am not nearly as
skilled with compilers as I’d like to be. I can get a very simple C++
program
with SDL to compile and run in Linux. I cannot however get it to compile
for
Windows. I have done a bit of cross-compiling for Windows, but it was so
simple
no libraries were included. When I try to compile for Windows, the SDL.h
file is
not found which makes me think I am not pointing to libraries properly.
Does
anyone have experience with this or know where I could find a handy
resource for
something such as this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Rogelio Nodal