Recent

Author Topic: Cross-compiling with Lazarus (host Win32/target Win64)  (Read 14371 times)

AMarchant

  • New Member
  • *
  • Posts: 15
Cross-compiling with Lazarus (host Win32/target Win64)
« on: October 03, 2010, 12:31:55 am »
Hi

I'd be very grateful if someone could clear up my confusion: I've been looking at the FPC wiki, and I've read lots of other related messages on different discussion forums, but I still haven't been able to figure out exactly what needs to be done to configure Lazarus for cross-compiling.

I'm using the most recent Lazarus release (Win32 0.9.28.2 beta - with FPC 2.2.4) and I have the ppcrossx64.exe binary (in the Lazarus\FPC\bin\ directory), but I think I understand from what I've read that this compiler needs to rebuild some or all RTL/LCL files in order to create a 64-bit executable.
The FPC wiki says

Quote
Win32 To Win64

If you are compiling the 2.1.1 or greater branch of fpc you can just do:

$ make all OS_TARGET=win64 CPU_TARGET=x86_64

and then

$ make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64

...I'm having trouble figuring out whether all of the files necessary for this are supplied in the FPC directory of the Lazarus install folder. I've tried calling make with the arguments above from the $(lazarus)\fpc\2.2.4\source\rtl directory, where a make file resides, but that ultimately fails with a

Quote
Fatal: Unknown compilerproc "fpc_char_to_uchar".

...error.

I'd really appreciate it if someone could put me on the right track.
« Last Edit: October 03, 2010, 12:36:37 am by AMarchant »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Cross-compiling with Lazarus (host Win32/target Win64)
« Reply #1 on: October 04, 2010, 10:07:25 am »
make sure you have all the compilers in the same version, type ppcx86 and ppcrossx64 at the command prompt to see it.

AMarchant

  • New Member
  • *
  • Posts: 15
Re: Cross-compiling with Lazarus (host Win32/target Win64)
« Reply #2 on: October 14, 2010, 08:38:09 pm »
Leledumbo, thanks for the reply. I came across another thread a little while ago that set out exactly what needed to happen. It's the most detailed, concise, and immediately accessible account I've found so far - perhaps someone could consider duplicating it amongst the official documentation. The thread was this one:

http://lazarus.firmos.at/index.php?topic=3592.0

I only changed a few things to suit my particular requirements (e.g., Zaher's instructions were for compiling ARM code on Intel/Win32 architecture, I wanted to compile a 64-bit Windows DLL on a 32-bit Windows PC). I've recreated his instructions below, modified with this end in mind.
The instructions assume you haven't yet acquired and installed Lazarus, so skip to the appropriate part if you've already got it installed.

Quote
1) Download Lazarus from an official source, SourceForge has a series of rotating mirrors, so that's a good place to look, it means less bandwidth draw from freepascal.org - http://sourceforge.net/projects/lazarus/

At the time of writing, the stable release is 0.9.28.2, and the bundled Free Pascal (FPC) package is 2.2.4 - make a note of these version numbers (they're written on the big green "Download Now!" button on SourceForge - the caption will appear in a mouse hint if you put your cursor over it should the entire text not be visible).

Run the installer, and follow instructions. I'm assuming you'll choose the default installation directory (c:\lazarus).

2) Create a subdirectory in the c:\lazarus folder called source - e.g., c:\lazarus\source
Create a subdirectory below the source directory called fpc
Create a subdirectory below the source directory called lazarus

...so now you should have

c:\lazarus\source\lazarus  and
c:\lazarus\source\fpc

3) Download the Free Pascal source code files (that correspond to the version bundled with Lazarus) from the freepascal.org FTP server - clicking the link below should allow you to browse all available versions. e.g., select - if you're using the same release of Lazarus I'm describing - the 2.2.4 directory, then the source directory, then right-click and choose Save As on the fpc-2.2.4.source.tar.gz or fpc-2.2.4.source.zip file - For What It's Worth, the open source archiver 7-Zip can decompress either of these ( http://www.7-zip.org/ ).

ftp://ftp.freepascal.org/pub/fpc/dist/

When you extract these files, make the destination folder c:\lazarus\source\fpc

4) Download the Lazarus source code files (that correspond to the version bundled with Lazarus) from SourceForge:

http://sourceforge.net/projects/lazarus/files/Lazarus%20Zip%20_%20GZip/

...e.g., right-click and choose Save As on the lazarus-0.9.28.2-src.tar.bz2 or lazarus-0.9.28.2-src.zip file.

When you extract these files, make the destination folder c:\lazarus\source\lazarus

5) Open a console window (pre WinNT click Start, choose Run, type command press enter, post WinNT, click Start, choose run, type CMD press enter).

6) Navigate to the Free Pascal source directory, typing:

cd\lazarus\source\fpc

7) Execute the following series of commands, as written, pressing Enter after each line (if you've installed a more recent version of Lazarus, adapt the values below to match - e.g., the '2.2.4' might need to be changed to '2.4.0' etc.):

set fpcdir=C:\lazarus\fpc\2.2.4
set path=%fpcdir%\bin\i386-win32;%path%
make all install INSTALL_PREFIX=%fpcdir%
make all install CROSSCOMPILE=1 OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=%fpcdir%
copy .\compiler\ppcrossx64.exe %fpcdir%\bin\i386-win32\*.*

NOTE: Using the ppcrossx64.exe compiler generated from the FPC 2.2.4 code I receive the error message:

"win32wsextdlgs.pp(204,1) Error: resource compiler not found, switching to external mode"

...when running step 7 (below). This DID NOT occur when I compiled ppcrossx64.exe from the FPC snapshot source (version 2.4.0 or later - so if you're using that version, or a more recent one, skip to step 7).
To cure it, I followed this advice from the FPC forum:

"make a copy of GoRC.exe from the c:\lazarus\fpc\2.2.4\bin\i386-win32 directory, rename this copy 'x86_64-win64-gorc.exe', then copy it back to the same directory"

7) Navigate to the Lazarus directory (note: NOT the Lazarus source directory!), e.g.,

cd\lazarus

8) Execute the following command:

make lcl LCL_PLATFORM=win32 PP=ppcrossx64.exe CPU_TARGET=x86_64 OS_TARGET=win64

9) You should now be able to compile 64-bit executables from your 32-bit Windows PC, e.g., to compile a Delphi project file called Test.dpr from the command line, do something like:

set path=%path%;c:\lazarus\fpc\2.2.4\bin\i386-win32

ppcrossx64.exe -MDelphi -Scghi -O3 -vewnhi -l -Twin64 -Rintel -Xs -Fu"C:\lazarus\lcl\units\x86_64-win64\" -Fu"C:\lazarus\lcl\units\x86_64-win64\win32\" Test.dpr

...you will need to add extra -Fu entries to include directories for any source/compiled (.pas, .dcu, .pp, .ppu) files used by your project that are not listed explicitly in the project .dpr file (e.g., the directories that would normally be listed in the Delphi/Lazarus IDE to be included), and extra -Fi to include directories containing any required .inc files (note: if you use files in a folder containing both .pas AND .inc files, you'll need a -Fu and a -Fi for this directory!).

Hope that makes some sort of sense and that I haven't made any mistakes....

 

TinyPortal © 2005-2018