User:CCRDude

From Free Pascal wiki
Jump to navigationJump to search

Lazarus and WinCE using Win64, from the start

Introduction

Existing tutorials

This is not to say that the existing tutorials are bad, just that they did not help in my special case. I gave up following them because of a bunch of things I couldn't follow, including PocketCMD, which doesn't run on my iPAQ H3870, the Microsoft Emulator which doesn't network on 64-bit Windows XP, unit paths in the tutorial that were not correct, and some other troubles. So I thought I'ld better understand what's done and write down my steps that way (because the next FPC + Lazarus version is surely to come...).

Prerequisites

I want to build simple GUI applications for a HP iPAQ H3870 running Pocket PC 2002 Version 3.0.11171 on an ARM SA1110 processor.

This tutorial is intended to show an installation of Lazarus to compile WinCE applications on a clean system running Windows (in this special case Windows XP 64-bit edition, but since all tools are 32-bit tools, it should run on standard Windows XP as well). Instructions are based on these Lazarus wiki pages:

Lazarus daily snapshot success

  • Lazarus-0.9.17-20060608-win32.exe: did not work on Win64 (linker problems)
  • Lazarus-0.9.17-20060610-win32.exe: works fine on Win32
  • Lazarus-0.9.17-20060612-win32.exe: did not work on Win32 (FCL does not compile)
  • Lazarus-0.9.17-20060615-win32.exe: works fine on Win64 (linker problem solved!)

Installation

Note: there's a batch file that does all the steps after downloading and extracting at the end of this file!

Cleanup

Completely remove old FPC and Lazarus installations. This includes opening the System Properties, Advanced tab, button Environment Variables, and removing all previous references to FPC and Arm in the PATH environment.

ARM-Utilities

  • Download arm-wince-binutils and extract into C:\Apps\arm\. Then add C:\Apps\arm to the PATH environment.
  • Test the path by opening a new terminal (Start -> Run -> 'cmd') and typing arm-wince-ar. If you see a compiler message, everything is fine.

Lazarus

  • Download newest Lazarus daily snapshot and install into C:\Apps\Lazarus\.
  • Add C:\Apps\Lazarus\pp\bin\i386-win32 and C:\apps\Lazarus\pp\bin\arm-wince to the PATH environment.
  • Test the path by opening a new terminal (Start -> Run -> 'cmd') and typing 'fpc'. If you see a compiler message, everything is fine.
  • The installation should be tested by compiling a simple existing Lazarus project.

FreePascal

By using a daily snapshot, we already have a 2.1.x version of FreePascal that is needed. But we still need some more FreePascal stuff. The other tutorials mentions Subversion; it's a bit simpler to get a daily snapshot of the development tree though, or directly via ftp. Open this archive and extract the folders from the fpc subfolder into C:\Apps\Lazarus\pp\. Make sure you don't have an additional fpc subfolder, but the compiler, fcl, etc. folder directly in pp.

Compiling for ARM

Create cross compiler

  • Open a new command prompt and switch to C:\Apps\Lazarus\pp\compiler.
  • Type make --help and check if you've got the right version (Delphi users will probably see the Borland version, in which case you should type set path=C:\Apps\arm;C:\Apps\Lazarus\pp\bin\i386-win32;C:\Apps\Lazarus\pp\bin\arm-wince).
  • Then just type make cycle CPU_TARGET=arm OS_TARGET=wince and let it compile. There'll be a bunch of warnings, hints and notes, but it should finish.
 C:
 cd \Apps\Lazarus\pp\compiler
 set path=C:\Apps\arm;C:\Apps\Lazarus\pp\bin\i386-win32;C:\Apps\Lazarus\pp\bin\arm-wince
 make cycle CPU_TARGET=arm OS_TARGET=wince

Files

  • Create the folder C:\Apps\Lazarus\pp\bin\arm-wince, and copy C:\Apps\Lazarus\pp\compiler\ppcrossarm.exe into it.
  • Create C:\Apps\Lazarus\pp\units\arm-wince\rtl, and copy C:\Apps\Lazarus\pp\rtl\units\arm-wince\*.* into it.
 mkdir C:\Apps\Lazarus\pp\bin\arm-wince
 copy C:\Apps\Lazarus\pp\compiler\ppcrossarm.exe C:\Apps\Lazarus\pp\bin\arm-wince\
 mkdir C:\Apps\Lazarus\pp\units\arm-wince\rtl
 copy C:\Apps\Lazarus\pp\rtl\units\arm-wince\*.* C:\Apps\Lazarus\pp\units\arm-wince\rtl\

Configuration

Go back to C:\Apps\Lazarus\pp\bin\arm-wince and create a fpc.cfg in there:

 -Twince
 -FuC:\Apps\Lazarus\pp\units\arm-wince
 -FuC:\Apps\Lazarus\pp\units\arm-wince\*
 -FuC:\Apps\Lazarus\pp\units\arm-wince\rtl
 -XParm-wince-
 -FDC:\Apps\arm
 -FDC:\Apps\Lazarus\pp\bin\arm-wince

FCL

  • Go to C:\Apps\Lazarus\pp\fcl and compile there.
  • Create C:\Apps\Lazarus\pp\units\arm-wince\fcl, and copy C:\Apps\Lazarus\pp\fcl\units\arm-wince\*.* into it.
 C:
 cd \Apps\Lazarus\pp\fcl
 make CPU_TARGET=arm OS_TARGET=wince PP=ppcrossarm.exe
 mkdir C:\Apps\Lazarus\pp\units\arm-wince\fcl
 copy C:\Apps\Lazarus\pp\fcl\units\arm-wince\*.* C:\Apps\Lazarus\pp\units\arm-wince\fcl\

LCL

Go to C:\Apps\Lazarus and rebuild the lcl.

 C:
 cd \Apps\Lazarus
 make lcl LCL_PLATFORM=wince PP=ppcrossarm.exe CPU_TARGET=arm OS_TARGET=wince


Batch file

This batch file does everything after downloading and installing/extracting the three archives.

@echo off

 set x_lazdir=C:\Apps\Lazarus
 set x_armdir=C:\Apps\arm
 set x_fpcsvnrelease=-r 3873
 cls
 echo ------------------------------------------------------------------------
 echo            arm-wince installation for FreePascal and Lazarus
 echo ------------------------------------------------------------------------
 echo You need to prepare the following:
 echo 1. Install the arm-binutils into %x_armdir%
 echo    ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip
 echo 2. Install the latest Lazarus daily into %x_lazdir
 echo    http://www.hu.freepascal.org/lazarus/
 echo 3. Install the latest FreePascal snapshot into %x_lazdir%\pp
 echo    (NOT inside another fpc subfolder as the archive structure suggests)
 echo    ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/source/fpc.zip
 echo OR you need to have svn installed and available.
 echo ------------------------------------------------------------------------
 if NOT EXIST %x_armdir%\arm-wince-ld.exe goto errorarmmissing
 if NOT EXIST %x_lazdir%\startlazarus.exe goto errorlazarusmissing
 if DEFINED APR_ICONV_PATH GOTO nosourcenecessary
 if NOT EXIST %x_lazdir%\pp\compiler\cclasses.pas goto errorfpcmissing
 :nosourcenecessary
 if NOT DEFINED APR_ICONV_PATH GOTO nosvndownload
 echo ------------------------------------------------------------------------
 echo Going to download FPC from SVN now... if this version does not work,
 echo please edit this file and change x_fpcsvnrelease accordingly.
 echo ------------------------------------------------------------------------
 cd %x_lazdir%
 svn checkout %x_fpcsvnrelease% http://svn.freepascal.org/svn/fpc/trunk pp
 ; svn update .
 :nosvndownload
 pause
 echo The necessary files were found, you may now continue.
 pause
 echo ------------------------------------------------------------------------
 echo The cross compiler will now be created...
 echo ------------------------------------------------------------------------
 C:
 cd %x_lazdir%\pp\compiler
 set path=%x_armdir%;%x_lazdir%\pp\bin\i386-win32;%x_lazdir%\pp\bin\arm-wince;%APR_ICONV_PATH%
 make cycle CPU_TARGET=arm OS_TARGET=wince
 echo ------------------------------------------------------------------------
 echo If you don't see any error messages, you may now continue.
 echo ------------------------------------------------------------------------
 pause
 echo Creating the folder %x_lazdir%\pp\bin\arm-wince ...
 mkdir %x_lazdir%\pp\bin\arm-wince
 echo Copying %x_lazdir%\pp\compiler\ppcrossarm.exe
 echo      to %x_lazdir%\pp\bin\arm-wince\ ...
 copy %x_lazdir%\pp\compiler\ppcrossarm.exe %x_lazdir%\pp\bin\arm-wince\
 echo Creating the folder %x_lazdir%\pp\units\arm-wince\rtl ...
 mkdir %x_lazdir%\pp\units\arm-wince\rtl
 echo Copying %x_lazdir%\pp\rtl\units\arm-wince\*.*
 echo      to %x_lazdir%\pp\units\arm-wince\rtl\ ...
 copy %x_lazdir%\pp\rtl\units\arm-wince\*.* %x_lazdir%\pp\units\arm-wince\rtl\
 echo Creating %x_lazdir%\pp\bin\arm-wince\fpc.cfg ...
 echo -Twince > %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -Fu%x_lazdir%\pp\units\arm-wince >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -Fu%x_lazdir%\pp\units\arm-wince\* >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -Fu%x_lazdir%\pp\units\arm-wince\rtl >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -XParm-wince- >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -FD%x_armdir% >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo -FD%x_lazdir%\pp\bin\arm-wince >> %x_lazdir%\pp\bin\arm-wince\fpc.cfg
 echo ------------------------------------------------------------------------
 echo The FCL will now be compiled...
 echo ------------------------------------------------------------------------
 pause
 cd %x_lazdir%\pp\fcl
 make CPU_TARGET=arm OS_TARGET=wince PP=ppcrossarm.exe
 echo Creating the folder %x_lazdir%\pp\units\arm-wince\fcl ...
 echo Copying %x_lazdir%\pp\fcl\units\arm-wince\*.*
 echo      to %x_lazdir%\pp\units\arm-wince\fcl\ ...
 mkdir %x_lazdir%\pp\units\arm-wince\fcl
 copy %x_lazdir%\pp\fcl\units\arm-wince\*.* %x_lazdir%\pp\units\arm-wince\fcl\
 echo ------------------------------------------------------------------------
 echo The LCL will now be compiled...
 echo ------------------------------------------------------------------------
 pause
 cd %x_lazdir%
 make lcl LCL_PLATFORM=wince PP=ppcrossarm.exe CPU_TARGET=arm OS_TARGET=wince
 echo ------------------------------------------------------------------------
 echo Congratulations!
 echo ------------------------------------------------------------------------
 goto EOF
 ;
 :errorarmmissing
 echo ------------------------------------------------------------------------
 echo The ARM files are missing in %x_armdir%!
 echo Please install them, then restart this batch file.
 echo .
 echo You can download these files from
 echo ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip
 echo .
 echo If you want to use different paths, please open this file in notepad
 echo and change the second and third line according to your wishes.
 echo ------------------------------------------------------------------------
 goto :EOF
 ;
 :errorlazarusmissing
 echo ------------------------------------------------------------------------
 echo The Lazarus installation is missing in %x_lazdir%!
 echo Please install a Lazarus daily, then restart this batch file.
 echo .
 echo You can download it from
 echo http://www.hu.freepascal.org/lazarus/
 echo .
 echo If you want to use different paths, please open this file in notepad
 echo and change the second and third line according to your wishes.
 echo ------------------------------------------------------------------------
 goto :EOF
 ;
 :errorfpcmissing
 echo ------------------------------------------------------------------------
 echo The FPC files are missing in %x_lazdir%\pp\!
 echo Please install them, then restart this batch file.
 echo Make sure you don't have them in the subfolder fpc, but directly in pp!
 echo .
 echo You can download these files from
 echo ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/source/fpc.zip
 echo .
 echo If you want to use different paths, please open this file in notepad
 echo and change the second and third line according to your wishes.
 echo ------------------------------------------------------------------------
 goto :EOF
 ;
 :EOF
 cd %x_lazdir%
 set x_lazdir=
 set x_armdir=
 set x_fpcsvnrelease=

Using Lazarus

  • Create a new application
  • Open the compile options,
    • change widgetset to wince,
    • target OS to WinCE,
    • and target processor to arm.
  • Change the compiler path in environment settings to C:\Apps\Lazarus\pp\bin\arm-wince\ppcrossarm.exe.