PDA

View Full Version : compile GNU/Linux binaries in Windows


Whistler
21-02-2005, 03:41
... It's just possible, this is what you need :)
http://filebase.bots-united.com/index.php?action=file&id=278

It's actually just a mere build of the MinGW source code with some extra configs, as MinGW and GNU/Linux version of gcc are actually the same code.

I don't actually encourage doing so btw... but it's somewhat good for people who use Windows only

(don't forget gcc is free software (http://www.gnu.org/philosophy/free-sw.html), and we have rights to do anything we want with it without the need to beg anyone!)

koraX
21-02-2005, 09:37
binaries can be compiled ?
what is this program doing ?
Does it compile source code ? If so, does it have support for SUSv3 (http://www.opengroup.org/onlinepubs/009695399/index.html) or LSBSv2.01 (http://www.linuxbase.org/) under windows ?

Whistler
21-02-2005, 12:27
it's just a GCC built under Windows in this way:
./configure --prefix=c:/gcc-gnulinux --target=i686-pc-linux-gnu
make
make install

Actually MinGW and *NIX gcc are the same code, this just enabled the GNU/Linux compiling instead of default MinGW Windows compiling. It should compile the same as GNU/Linux, but perhaps you need some extra libraries to compile something other than bots.

Pierre-Marie Baty
21-02-2005, 16:05
Can it do cross-compiles? I'd be interested in compiling native Linux binaries for my metamod stuff without needing to upload my sources each time on the BU server.

sPlOrYgOn
21-02-2005, 19:29
I just tried it with pbmm but it seems to create a .so file twice the size of when it is compiled on linux and also gets a badf load...:(
can i compile on the BU server too?

Pierre-Marie Baty
21-02-2005, 20:55
Anybody who has a shell account on the BU machine can compile his plugins... but I think you don't have one yet because you don't have any website for your bot. One more reason to change that :)

Whistler
22-02-2005, 02:40
well I've found the problem... try NOT to use "-march" parameter (like -march=i586 or so) and use "_i386.so" as the end of the filename and it should work in Metamod

also note that "gcc" is the C compiler, and "g++" is the c++ compiler so make sure you are compiling C++ code with "g++" command.

but the file size is still big, as it's totally staticly linked.

Whistler
22-02-2005, 06:22
well you also need to use the "-static" parameter...

here's the work Makefile

CPP = g++
TARGET = podbot_mm
BASEFLAGS = -Dstricmp=strcasecmp -Dstrcmpi=strcasecmp
OPTFLAGS = -DNDEBUG
CPPFLAGS = ${BASEFLAGS} ${OPTFLAGS} -O2 -w -I"../metamod-1.17/metamod" -I"../hlsdk/multiplayer/common" -I"../hlsdk/multiplayer/dlls" -I"../hlsdk/multiplayer/engine" -I"../hlsdk/multiplayer/pm_shared"

OBJ = bot.o \
bot_chat.o \
bot_client.o \
bot_combat.o \
bot_globals.o \
bot_sounds.o \
compress.o \
dll.o \
engine.o \
util.o \
waypoint.o

${TARGET}_i386.so: ${OBJ}
${CPP} -fPIC -shared -static -o $@ ${OBJ} -ldl -lm

clean:
rm -f *.o
rm -f *.map

%.o: %.cpp
${CPP} ${CPPFLAGS} -c $< -o $@

%.o: %.c
${CPP} ${CPPFLAGS} -c $< -o $@


looks like it's still far from being perfect :(

KaCaT
22-02-2005, 09:07
Works fine, thanks! :)

btw, I've just found another similiar way to compile win32 binaries from linux 8D:
http://www.wxwidgets.org/technote/crosscmp.htm

Pierre-Marie Baty
22-02-2005, 15:30
Yes, and I believe that's what Will Day does with metamod, he compiles everything on GNU/Linuts :)

The Storm
22-02-2005, 18:02
Can someone explain me how to compile with this EPB. It will be good to have a linux version.

sfx1999
22-02-2005, 18:12
So, how do I cross compile for the PDP-11? :P

Whistler
23-02-2005, 04:17
"Can someone explain me how to compile with this EPB. It will be good to have a linux version."
just create a file named "Makefile" in your source directory, like this one:

CPP = g++
TARGET = epb
BASEFLAGS = -Dstricmp=strcasecmp -Dstrcmpi=strcasecmp
OPTFLAGS = -DNDEBUG
CPPFLAGS = ${BASEFLAGS} ${OPTFLAGS} -O2 -w -I"./hlsdk"

OBJ = bot.o
bot_chat.o
bot_client.o
bot_combat.o
bot_globals.o
bot_sounds.o
compress.o
dll.o
engine.o
util.o
waypoint.o

${TARGET}_i386.so: ${OBJ}
${CPP} -fPIC -shared -static -o $@ ${OBJ} -ldl -lm

clean:
rm -f *.o
rm -f *.map

%.o: %.cpp
${CPP} ${CPPFLAGS} -c $< -o $@

%.o: %.c
${CPP} ${CPPFLAGS} -c $< -o $@


(note that you MUST have a backslash after each ".o" file; the forum has bugs which ate up all backslashes)

write all your .cpp files in the list, change all .cpp to .o.

Then install the compiler, start a DOS prompt, run the setvars.bat file first and change into your source dir. Then run "make" and it should produce a epb_i386.so file and that's it.

Pierre-Marie Baty
23-02-2005, 16:05
(note that you MUST have a backslash after each ".o" file; the forum has bugs which ate up all backslashes)
I wonder what it would be like with the [ code ] tags instead...

CPP = g++
TARGET = epb
BASEFLAGS = -Dstricmp=strcasecmp -Dstrcmpi=strcasecmp
OPTFLAGS = -DNDEBUG
CPPFLAGS = ${BASEFLAGS} ${OPTFLAGS} -O2 -w -I"./hlsdk"

OBJ = bot.o \\
bot_chat.o \\
bot_client.o \\
bot_combat.o \\
bot_globals.o \\
bot_sounds.o \\
compress.o \\
dll.o \\
engine.o \\
util.o \\
waypoint.o

${TARGET}_i386.so: ${OBJ}
${CPP} -fPIC -shared -static -o $@ ${OBJ} -ldl -lm

clean:
rm -f *.o
rm -f *.map

%.o: %.cpp
${CPP} ${CPPFLAGS} -c $< -o $@

%.o: %.c
${CPP} ${CPPFLAGS} -c $< -o $@

*edit* damn, yer right.
I'd better look into that someday.

The Storm
23-02-2005, 17:27
It's not working :
here is the error messege:
make : <e=2>:
make : *** [EPB_i386.so] Error 2

Whistler
24-02-2005, 02:25
in which step this error happened? would you post the full output?

(also you need to add the log.o to the list in Makefile if you haven't deleted it, and if you've created new files you need to add them as well)

The Storm
24-02-2005, 23:23
Here :

dll.cpp:20: error: expected `>` before '*' token
dll.cpp:20: error: expected `,` or `;` before '*' token
dll.cpp:22: error: expected `>` before '*' token
dll.cpp:22: error: expected `,` or `;` before '*' token
dll.cpp:29: error: `GETNEWDLLFUNCTIONS` does not name a type
make: *** [dll.o] Error 1

The strange is that when I compile it with MSVC there is no problem.

Whistler
25-02-2005, 02:29
then it's bacause something GNU/Linux specific is missing in the code... you gotta fix it first
search for "__linux__" in HPB bot and you'll see what's required

edit: I think this is the problem:

// stuff for Win32 vs. Linux builds

#ifndef __linux__

typedef int (FAR *GETENTITYAPI)(DLL_FUNCTIONS *, int);
typedef int (FAR *GETNEWDLLFUNCTIONS)(NEW_DLL_FUNCTIONS *, int *);
typedef void (DLLEXPORT *GIVEFNPTRSTODLL)(enginefuncs_t *, globalvars_t *);
typedef void (FAR *LINK_ENTITY_FUNC)(entvars_t *);

#else

#include <dlfcn.h>
#define GetProcAddress dlsym

typedef int BOOL;

typedef int (*GETENTITYAPI)(DLL_FUNCTIONS *, int);
typedef int (*GETNEWDLLFUNCTIONS)(NEW_DLL_FUNCTIONS *, int *);
typedef void (*GIVEFNPTRSTODLL)(enginefuncs_t *, globalvars_t *);
typedef void (*LINK_ENTITY_FUNC)(entvars_t *);

#endif

and it seems that in POD-Bot the GETNEWDLLFUNCTIONS isn't declared after the #else.

The Storm
26-02-2005, 10:50
Thanks you Whistler. You was write ! The problem was in bot.h.
Now I succseful compile EPB for Linux. With the next release I will publish and the Linux version of EPB.
Thnaks you again.

EDIT : Did I must publish the source code of EPB if I publish a Linux version ?

Whistler
27-02-2005, 03:29
"Did I must publish the source code of EPB if I publish a Linux version ?"
Nope, as you are just *USING* gcc, which is totally free and not restricted :)
perhaps you can read through the GPL to see in which case you need to release the sources.

sfx1999
27-02-2005, 04:06
The PDP-11 is too new anyway. How do I cross compile for the ENIAC?

Whistler
27-02-2005, 04:19
"The PDP-11 is to new anyway. How do I cross compile for the ENIAC?"
I don't think ENIAC uses software :) AFAIK you have to change the hardware to make programs in ENIAC

for PDP-11 there are several emulators and nowadays AT&T UNIX is free software, so you may find those ones :)

sfx1999
27-02-2005, 06:45
Oops! I just fixed an error in my last post.

Anyway, I think it is kind of funny that GCC supports the PDP-11. I mean, the machine is so damn old. I have never even seen one.

FrostyCoolSlug
11-04-2005, 06:15
As a note, mingw won't nessecerily compile ALL linux apps to windows, for example, anything which acts as a socket server (for whatever reason) requires the use of winsock, NOT the standard *nix socket.h you can use defines for it all, but it will get messy. For use in bots, its a 'quick fix', but don't expect it to hold out too well, POSIX is still a long way from being ported properly to windows (Hence the larger files).

As another note, cygwin doesn't support Shared Objects.. its a lose lose situation if you have something with both ;)

Whistler
14-06-2005, 16:21
I've rebuilt the compiler and now it is GCC 2.95 so that it can build HPB bot straightly... and there is also no need to use "-static" now

you may want to redownload it

The Storm
01-07-2005, 12:53
Whislter where is setvars.bat file? I can't compile in this way. :(

Whistler
01-07-2005, 14:14
use this command:
path c:\gcc-gnulinux\bin;%path%

Pierre-Marie Baty
01-07-2005, 18:09
Could you make it so that the install dir is changeable ?

The Storm
01-07-2005, 20:14
Could you make it so that the install dir is changeable ?

I think that is only needed to change the command :

path c:\gcc-gnulinux\bin;%path%

with the dir that you are moved the folder.
For drive D: it will be :

path D:\gcc-gnulinux\bin;%path%

Pierre-Marie Baty
01-07-2005, 20:50
I'm not sure. The GNU linker is weird. Whistler certainly knows more about it.

Whistler
02-07-2005, 07:01
Maybe you will need to recompile the source code, as the path is hardcoded in the executable.

I'm not sure if setting the GCC_EXEC_PREFIX environment variable to the correct path and add a whole bunch of -I and -L parameters to the commandline will work, I haven't tried this. See the gcc manuals for details.