# Cross-Compiling an existing linux SDL-Project on win32 and macos

**URL:** <https://discourse.libsdl.org/t/cross-compiling-an-existing-linux-sdl-project-on-win32-and-macos/11348>\
**Category:** SDL Development\
**Created:** [October 5, 2004, 4:48pm UTC](https://discourse.libsdl.org/t/cross-compiling-an-existing-linux-sdl-project-on-win32-and-macos/11348 "2004-10-05T16:48:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_Dawitz](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sven_dawitz/32/1403_2.png) [@Sven\_Dawitz](https://discourse.libsdl.org/u/Sven_Dawitz)\
**Post date:** [October 5, 2004, 4:48pm UTC](https://discourse.libsdl.org/t/cross-compiling-an-existing-linux-sdl-project-on-win32-and-macos/11348/1 "2004-10-05T16:48:16Z")

</div>

Hi!

We are developing battletaxi - a multiplayer/networking space-taxi clone with lots of weapons. (will be released/added to [libsdl.org/sourceforge](http://libsdl.org/sourceforge) soon)

We tried to compile the working linux project on windows and on macos - see my problems below

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* MAC OS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
i tried the compiling at a friends g4-notebook with latest macos (i guess it was 10.2) and gcc 3.3  
i compiled a helloworld.c (which worked) to check, if compiler is okay

now, if i complile the objects with  
gcc -DPACKAGE\_NAME="" -DPACKAGE\_TARNAME="" -DPACKAGE\_VERSION="" -DPACKAGE\_STRING="" -DPACKAGE\_BUGREPORT="" -DPACKAGE=“SDL\_tests” -DVERSION=“1.2.7” ?-I.-I. ? ? -g -O2 -I /usr/include/SDL -Dmain=SDL\_main -DHAVE\_OPENGL -c battletaxi.c  
this works fine without errors

in the last step i invoke the linker with  
gcc -Wall -v -v -v ?-g -O2 -I/usr/include/SDL -Dmain=SDL\_main -DHAVE\_OPENGL \*.o ?-o battletaxi.mac -L/sw/lib -lSDL -lSDL\_mixer -lSDL\_image ?-Wl,/usr/lib/libobjc.A.dylib

that gives the following error:

Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs  
Thread model: posix  
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)  
?ld -arch ppc -dynamic -o battletaxi.mac -lcrt1.o -lcrt2.o -L/sw/lib -L/usr/lib/gcc/darwin/3.3 -L/usr/lib/gcc/darwin -L/usr/libexec/gcc/darwin/ppc/3.3/…/…/… background.o battletaxi.o bubble.o drawings.o fonts.o game.o highscore.o hud.o input.o level.o man.o menu.o taxi.o weapons.o -lSDL -lSDL\_mixer -lSDL\_image /usr/lib/libobjc.A.dylib -lgcc -lSystem |  
?c++filt3  
ld: Undefined symbols:  
\_main

i dont know, why gcc doesnt know \_main - did i forgot to link some lib, or what ? why did my helloworld.c work ?

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* WINDOWS \*\*\*\*\*\*\*\*\*\*\*\*\*/  
i use MinGW/MSYS under WXP. I compiled all needed SDL\_Libraries, which run just fine. If i modify the source to fix below problems “by hand”, i get a  
working w32 .exe file

------ W32-PROBLEM 1  
the first big problem is that i have to call SDL\_Init() other on windows:  
linux: ? ? ? ?tscreen = SDL\_SetVideoMode (aw, ah, ad, SDL\_HWSURFACE|SDL\_DOUBLEBUF|SDL\_ASYNCBLIT|SDL\_FULLSCREEN);  
windows: tscreen = SDL\_SetVideoMode (aw, ah, ad, SDL\_ASYNCBLIT|SDL\_FULLSCREEN);

i dont get a HWSURFACE on windows - is that usual ?

------ W32-PROBLEM 2  
the problem i have at linking is, that SDL\_gfx calls produce errors - even i installed the SDL\_gfx.dll (plus headers) in the same dir as the other SDL\*.dll files  
if i have the following lines of code included:  
? ? ? ? lineRGBA(ascreen, abubble-\>x, abubble-\>y-20, abubble-\>bubblex+20, abubble-\>bubbley-40, 0x99, 0x99, 0x99, 0xFF);  
? ? ? ? lineRGBA(ascreen, abubble-\>x+1, abubble-\>y-20, abubble-\>bubblex+21, abubble-\>bubbley-40, 0x99, 0x99, 0x99, 0xFF);  
? ? ? ? filledEllipseRGBA(ascreen, abubble-\>bubblex+20, abubble-\>bubbley-70, abubble-\>textwidth/2+15, 30, 0x99, 0x99, 0x99, 0xFF);  
and i invoke the compiler the following way:  
gcc ?-g -O2 -I/mingw//include/SDL -Dmain=SDL\_main -DHAVE\_OPENGL ? -o battletaxi.exe \*.o -L/mingw//lib -lmingw32 -lSDLmain -lSDL -mwindows -lSDL\_mixer -lSDL\_image -lSDL\_gfx

i get the following error:  
bubble.o(.text+0x17a): In function `bubbleDraw': C:/winapps/develop/msys/home/Dave/workdir/battletaxi/bubble.c:52: undefined reference to`\_imp\_\_lineRGBA’  
bubble.o(.text+0x1b9):C:/winapps/develop/msys/home/Dave/workdir/battletaxi/bubble.c:53: undefined reference to `_imp__lineRGBA' bubble.o(.text+0x1fc):C:/winapps/develop/msys/home/Dave/workdir/battletaxi/bubble.c:54: undefined reference to`\_imp\_\_filledEllipseRGBA’

if i comment the above lines out, everything compiles fine and a get a working .exe

------ W32-PROBLEM 3  
another big problem i have under windows is the fullscreen toggle  
if i toggle fullscreen/windowed mode under windows. my program segfaults.  
here is my toggle code - which runs fine under linux:  
void switchfullscreen (void)  
{  
? ? ? ? SDL\_Surface \*tmp = SDL\_GetVideoSurface();  
? ? ? ? Uint32 flags;  
? ? ? ? int x,y,bpp;  
? ? ? ? if (tmp)  
? ? ? ? {  
? ? ? ? ? ? ? ? flags = tmp-\>flags ^ SDL\_FULLSCREEN;  
? ? ? ? ? ? ? ? x = tmp-\>w;  
? ? ? ? ? ? ? ? y = tmp-\>h;  
? ? ? ? ? ? ? ? bpp = tmp-\>format-\>BitsPerPixel;  
? ? ? ? ? ? ? ? SDL\_SetVideoMode (x, y, bpp, flags);  
? ? ? ? }  
}

what do i have to change, so it also works on win32 ?

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* GENERAL \*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
wouldnt it be an option to invoke gcc under linux in a way, that he cross-compiles binaries for macos/win32 ? if there is a way, could anyone provide  
me with some google search terms for doing so ? i would like to create w32 executables without rebooting - dynamic linking should work cross-plattform,  
if the .so/.dll files are installed…
