Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-01

Cross-compilation to Linux from win32

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Simon Kissel

Hi,

after quite some time I thought to give FPC another try to see if it's a suitable replacement for Kylix.

My goal is to be able to cross-compile Linux elf targets from win32.

So I downloaded and installed 1.9.6, and after that added the units packages for Linux.

Run up FP, compiled hello world, worked. Switched the target in FP to linux, compiled again - and wow, it also worked. Using the verbose output I could even see it using the Linux units etc. All fine.

Until I examined the generated executable "hello". It looks like it's a Linux binary packed into a PE file. Very weird. Doesn't run under Linux of course, and does nothing under Windows.

Next attempt was to use fpc directly:

C:\pp\demo\text>fpc -Aelf hello.pp
Free Pascal Compiler version 1.9.6 [2004/12/31] for i386 Copyright (c) 1993-2004 by Florian Klaempfl
Target OS: Win32 for i386
Compiling hello.pp
Linking hello.exe
31 Lines compiled, 0.4 sec

Well, no.

Some advise on what to do would be very welcome.

Thanks,

Simon

Reply by email

Peter Vreman
to Simon Kissel
Show quoted text 24 lines
Hi, after quite some time I thought to give FPC another try to see if it's a suitable replacement for Kylix. My goal is to be able to cross-compile Linux elf targets from win32. So I downloaded and installed 1.9.6, and after that added the units packages for Linux. Run up FP, compiled hello world, worked. Switched the target in FP to linux, compiled again - and wow, it also worked. Using the verbose output I could even see it using the Linux units etc. All fine. Until I examined the generated executable "hello". It looks like it's a Linux binary packed into a PE file. Very weird. Doesn't run under Linux of course, and does nothing under Windows. Next attempt was to use fpc directly: C:\pp\demo\text>fpc -Aelf hello.pp Free Pascal Compiler version 1.9.6 [2004/12/31] for i386 Copyright (c) 1993-2004 by Florian Klaempfl Target OS: Win32 for i386

The parameter -Tlinux is missing

Compiling hello.pp Linking hello.exe 31 Lines compiled, 0.4 sec

Reply by email

Unknown author
to Simon Kissel: after quite some time I thought to give FPC another try to see if it's a suitable…
Simon Kissel wrote 31 lines
Hi, after quite some time I thought to give FPC another try to see if it's a suitable replacement for Kylix. My goal is to be able to cross-compile Linux elf targets from win32. So I downloaded and installed 1.9.6, and after that added the units packages for Linux. Run up FP, compiled hello world, worked. Switched the target in FP to linux, compiled again - and wow, it also worked. Using the verbose output I could even see it using the Linux units etc. All fine. Until I examined the generated executable "hello". It looks like it's a Linux binary packed into a PE file. Very weird. Doesn't run under Linux of course, and does nothing under Windows. Next attempt was to use fpc directly: C:\pp\demo\text>fpc -Aelf hello.pp Free Pascal Compiler version 1.9.6 [2004/12/31] for i386 Copyright (c) 1993-2004 by Florian Klaempfl Target OS: Win32 for i386 Compiling hello.pp Linking hello.exe 31 Lines compiled, 0.4 sec Well, no. Some advise on what to do would be very welcome.

You can't do it using linux alone.

You must install cross-target binutils. Specifically: the linker must create a linux binary instead of a Windows binary.

Once you have those installed (there is a zip floating around somewhere) you must point the compiler to them with the -FD parameter.

Michael.

Reply by email

Unknown author
to Simon Kissel: after quite some time I thought to give FPC another try to see if it's a suitable…

----- Original Message -----

Earlier message 168 lines
From: "Simon Kissel" To: Sent: Friday, January 14, 2005 7:55 PM Subject: [fpc-pascal] Cross-compilation to Linux from win32 > Hi, > > after quite some time I thought to give FPC another try to see if it's > a suitable replacement for Kylix. > > My goal is to be able to cross-compile Linux elf targets from win32. > > So I downloaded and installed 1.9.6, and after that added the units > packages for Linux. > > Run up FP, compiled hello world, worked. Switched the target in FP to > linux, compiled again - and wow, it also worked. Using the verbose > output I could even see it using the Linux units etc. All fine. > > Until I examined the generated executable "hello". It looks like it's > a Linux binary packed into a PE file. Very weird. Doesn't run under > Linux of course, and does nothing under Windows. > > Next attempt was to use fpc directly: > > C:\pp\demo\text>fpc -Aelf hello.pp > Free Pascal Compiler version 1.9.6 [2004/12/31] for i386 > Copyright (c) 1993-2004 by Florian Klaempfl > Target OS: Win32 for i386 > Compiling hello.pp > Linking hello.exe > 31 Lines compiled, 0.4 sec > > Well, no. > > Some advise on what to do would be very welcome. > > Thanks, > > Simon > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal Hi, A cross compiler works on a specific operating system (the host) and compiles/links code for another processor/operating system (the target) I think one needs the following things to build a free pascal cross-compiler: 1. A cross compiler which can be executed/run on the host computer and compiles to the target computer. (as.exe will be the cross compiler ) 2. A cross linker which can be executed/run on the host computer and links to the target computer. ( ls.exe will be the cross linker ) 3. Free Pascal Compiled Units for the target computer. ( c:/pp/units/linux ) ( I don't know how to compile these units for the target computer, I downloaded them from somebody else ) Here are some steps/tips to help you ;) I build a free pascal cross compiler once. It compiles from win32 to linux. Here some tips: 1. Install Free Pascal ( Binary ) 2. Install CygWin ( Binary ) Download all developer things. 3. Install BinUtils-2.14 (or maybe another version) ( Source ) 4. Find somebody with compiled free pascal linux units. Place them in c:/pp/units/linux 5. Go in CygWin 6. Type: which make 7. Check if it's cygwin's make. If it's the wrong version than alter cygwin.bat and change the path so that only windows folders and this path is in it: c:\cygwin\bin 8. Go to the binutils folder To list folders and files type: ls To go to root type: cd c:/ To go to binutils type: cd /binutils-2.14 Make a new build folder by typing: mkdir build Type: cd build Type: ../configure --target=i686-linux This means it executes the program in the parent folder and places the output in the current folder which should be c:/binutils-2.14/build This configure program will make a new make file so that the binutils can be compiled for linux BinUtils contains a as.exe ( cross assembler ) and a ld.exe ( cross linker ) you need these two for the cross compiler. 9. Disable firewalls and virus scanners, plug the network cables. 10. Type: make It will take very long to make the new as-new.exe and ld-new.exe 11. After it's done you have two new files: as-new.exe is located in build\as\ ld-new.exe is located in build\ld\ 12. Execute as-new.exe with the parameter -v This parameter will show you if the target is indeed linux. If you get errors will doing this you are using the wrong cygwin1.dll. There could be multiple copies of cygwin1.dll on your system. The solution is to copy the cygwin1.dll file from c:\cygwin\bin to the as-new folder. 13. Copy as-new.exe to c:\pp\bin\linux and rename it to as.exe 14. Copy ld-new.exe to c:\pp\bin\linux and rename it to ld.exe 15. Change the windows path variable so that c:\cygwin\bin is removed from it. If you don't do this then free pascal cross compiler might use the wrong as.exe and ld.exe. 16. Make a simply hello world example and compile it like this: fpc -TLINUX hello.pas The result will be a linux executable without an extension. Go to linux and type: ./hello To run it. If you uploaded it to a linux machine via ftp or something and you are using ssh/putty whatever you might first need to give it execute permissions etc. Good luck to you. Bye, Skybuck.

Reply by email

Unknown author

Hi,

Little typo corrected :P

7. Check if it's cygwin's make. If it's the wrong version than alter

cygwin.bat and change the path so that only windows folders and this path is in it: c:\cygwin\bin

than should be then ;)

7. Check if it's cygwin's make. If it's the wrong version then alter cygwin.bat and change the path so that only windows folders and this path is in it: c:\cygwin\bin

This line is maybe not completely clear:

This configure program will make a new make file so that the binutils can

be compiled for linux

I think it is compiled for win32... but when running as-new.exe and ls-new.exe from win32 they will compile/link to linux ;)

Little typo here:

9. Disable firewalls and virus scanners, plug the network cables.

Should be:

9. Disable firewalls and virus scanners, unplug the network cables.

( Unplug for security ;) cygwin needs a lot of access to loopback etc your firewall will go crazy ;) better
is to simply disable the firewall )

Little typo here too:

If you get errors will doing this you are using the wrong cygwin1.dll.

There

Should be:

If you get errors while doing this you are using the wrong cygwin1.dll. There

could be multiple copies of cygwin1.dll on your system.

Bye,
Bye,
Skybuck =D

Reply by email

Unknown author

I have changed this line:

This configure program will make a new make file so that the binutils can

be

compiled for linux

To this:

This configure program will make a new make file so that the binutils can be compiled/linked for the host which is windows and use cygwin1.dll to work but so that the binutils themselfes compile/link to the target which is linux ;)

( I think that's what's going on :) )

Bye,
Skybuck.

Reply by email