Archived

This topic is now archived and is closed to further replies.

Compiling for win32 from linux (gcc)

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can currently compile and run my code on linux with the following makefile. The code is written to be compatible with windows (using cross platform libs like SDL), so as a next step I'm trying to compile an executable in the win32 format. My current makefile (for creating the linux executable) is below. I'm hoping to modify it to output the executable in the win32 format. I tried changing the nasm output format to coff instead of elf, but that wasn't enough and I really don't know what else to do. I've spent several hours RTFM on gcc so please don't just point me there.
OBJS=./src/main.o ./src/sdl.o ./src/input.o ./src/menu.o ./src/mapeng.o ./src/pp
e.o ./src/ai.o ./src/enemy.o ./src/player.o ./src/sse_mem.o ./src/rand.o
CFLAGS = $(shell sdl-config --cflags)
LIBS = $(shell sdl-config --libs) -lSDL_mixer

all: linux_app.exe

%.o: %.asm
        nasm -f elf -i ./include/ -l $*.lst $*.asm

%.exe: $(OBJS)
        gcc $(LIBS) -Wall -s -O3 -o linux_app $(OBJS)

clean:
        rm -f ./src/*.o linux_app ./src/*.lst
 
Any advice whatsoever is appreciated. I've been dabbling with this off and on for around a year w/o much luck. Thanks, --Ben [edited by - atreyu on February 20, 2004 9:14:22 AM]

Share this post


Link to post
Share on other sites
What ypu want to achieve is called cross compiling.
I don''t know the exacts step, actually I just know the term.

Maybe Google or some GCC newsgroups have some insight on this subject.

At least this is a better answers that rtfm page

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://wiki.wxwindows.org/wiki.pl?Cross-Compiling_Under_Linux

Share this post


Link to post
Share on other sites
OK, I followed the steps necessary to build a gcc cross compiler as outlined here. It must be close, but I''m running into what looks like linker errors still. Do I need to build a nasm-cross-compiler maybe?

Here''s an excerpt of the output:

bash-2.05b# ./cross-make.sh
nasm -f elf -i ./include/ -l src/main.lst src/main.asm
nasm -f elf -i ./include/ -l src/sdl.lst src/sdl.asm
nasm -f elf -i ./include/ -l src/input.lst src/input.asm
nasm -f elf -i ./include/ -l src/menu.lst src/menu.asm
nasm -f elf -i ./include/ -l src/mapeng.lst src/mapeng.asm
nasm -f elf -i ./include/ -l src/ppe.lst src/ppe.asm
nasm -f elf -i ./include/ -l src/ai.lst src/ai.asm
nasm -f elf -i ./include/ -l src/enemy.lst src/enemy.asm
nasm -f elf -i ./include/ -l src/player.lst src/player.asm
nasm -f elf -i ./include/ -l src/sse_mem.lst src/sse_mem.asm
nasm -f elf -i ./include/ -l src/rand.lst src/rand.asm
gcc -L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread -lSDL_mixer -Wall -s -O3 -o linux_app ./src/main.o ./src/sdl.o ./src/input.o ./src/menu.o ./src/mapeng.o ./src/ppe.o ./src/ai.o ./src/enemy.o ./src/player.o ./src/sse_mem.o ./src/rand.o
./src/main.o(.text+0x19): In function `main'':
: undefined reference to `printf''
./src/main.o(.text+0x41): In function `main.ValidArgc'':
: undefined reference to `strcmp''
./src/main.o(.text+0x7e): In function `main.DontAdjustNukes1'':
: undefined reference to `strcmp''
./src/main.o(.text+0xa5): In function `main.DontAdjustNukes2'':
: undefined reference to `strcmp''
./src/main.o(.text+0xd7): In function `main.DontAdjustNukes2'':
: undefined reference to `strcmp''
./src/main.o(.text+0xee): In function `main.DontReadSecondArg'':
: undefined reference to `printf''
./src/main.o(.text+0x2d8): In function `RunGame.SkipDrawingNukeIcons'':
: undefined reference to `fopen''

[continues for every library function used in the game]


Since gcc is really just acting as a linker (since all the code is in assembly) it''d make sense that nasm needs to be messed with. Do you think I need to find another version though or are there some flags I can specify in the makefile to get the .o files in the correct format?

Share this post


Link to post
Share on other sites