PDA

View Full Version : Compiling Linux programs in Windows



Relfos
15-12-2005, 11:52 AM
Hi there.
I tried to compile a sample program that displays "Hello world!" in FPC 2.0.2.
Changed the Target to Linux-i386, and installed Linux units into FPC folder, in units/i386-linux
The program compiled without errors, however I tried to run it in Linux, and I got "Permission denied" error. Then I changed file permissions with chmod, but still doesnt worked.


After comparing the binary files of the programs, I noticed Linux native programs have ELF in their header, while the one I compiled got MZ, wich is the same as programs compiled to windows. Am I doing something wrong?
Is there anyway to compile Linux programs under Windows using FPC?

Sly
15-12-2005, 01:07 PM
Did you specify -Tlinux on the command line?

Relfos
15-12-2005, 03:10 PM
Yes, I already tried that.
Compiles ok, but gives the following warning
"ld.exe: cannot find entry simbol _mainCRTstartup; defaulting to 00401000"
It seems that the FPC can only produce win32 binaries, changing the target doesnt seem to work. The final executable size is diferent from the win32 .exe, but doest run in Linux. Also if I change the file extension to .exe I able to run it in windows XP, but only console window appears, and then the program hangs.

Legolas
15-12-2005, 04:13 PM
You need a crosscompiler and cross binutils too. Look here (http://www.freepascal.org/wiki/index.php/Cross-compilation_from_Win32_to_GO32v2) for more infos. :wink:

Relfos
15-12-2005, 10:15 PM
Thanks for the info, I've already found some win32-linux cross compiler version of FPC. When I've some free time i'll test it.

Relfos
16-12-2005, 03:43 PM
Ok, I've tested it, and it worked :P
If someone is interested in known how to do it, I will explain it.

1A¬? Download the following BinUtils and extract it to your FPC\bin\i386-win32 folder:
ftp://ftp.freepascal.org/pub/fpc/contrib/cross/cygwin/

2A¬? Create a new folder FPC\units\i386-linux
Download FPC (Linux version, the big .tar file) and extract all units there.

3A¬? To compile your program (in the command line), do something like
fpc.exe sample.pas -TLinux -XPi686-linux-

The Cygwin cross binutils contains lots of files for diferente OS and processores, so probably this method can be used to compile to other targets, just install target units and change comand line arguments.