WinCE port

From Free Pascal wiki
Jump to navigationJump to search

WinCE port is quite complete and usable. The port was started and maintained by Yury Sidorov. Oliver (Oro06) ported WinCE API headers.

Status

  • The 2.1.x compiler has compiler support for WinCE.
  • ARM and i386 (old WinCE emulator) CPUs are supported.
  • The following platforms are supported:
    • Pocket PC 2002 – WinCE version: 3.0
    • Pocket PC 2003 – WinCE version: 4.20
    • Pocket PC 2003 Second Edition – WinCE version: 4.21
  • Base RTL units are complete.
  • Windows unit is almost complete. Delphi compatible declarations is not ready.

Building Tutorial

During the tutorial some paths will be suposed to demonstrate the build process. Just substitute those paths with the ones on your system.

Step 1 - Cross binutils

These are the basic tools necessary to create executables, such as: Linker (ld), Assembler (as), Archiver (ar) (Creates smartlinking .a files), strip and some others.

You need cross binutils for arm-wince, get them from ftp://ftp.freepascal.org/pub/fpc/contrib/cross/arm-wince-binutils.zip for Win32.

Extract them to some dir in the path on your machine. We will supose that you extracted the cross binutils to: C:\Programas\arm

Step 2 - Cross compiler

Now you need to build fpc cross compiler for ARM processor. To do that you need latest fpc 2.1.x sources and working installation of fpc 2.x for Win32.

Get the latest 2.1.x source repository from Subversion: http://www.freepascal.org/develop.html#svn

We will supose that you are using Win32 fpc compiler available with the Lazarus Snapshot, because this is a good tool to test the upcoming Windows CE widgetset. You can get Lazarus snapshots here.

In this case we will supose that your Win32 compiler is located here: C:\Programas\lazarus13\pp\bin\i386-win32

And you Free Pascal 2.1.x source code is located here: C:\Programas\fpc21

Step 3 - The Build process

In order to build the compiler it is necessary to have a correct PATH environment variable. On Windows it is very easy to get a PATH crowded with information put by installers. To ensure that your path is correct, create a batch file with the following code:

PATH=C:\Programas\lazarus13\pp\bin\i386-win32;c:\Programas\arm
make cycle CPU_TARGET=arm OS_TARGET=wince

Put this file on C:\Programas\fpc\compiler, open the Windows command line, go to this folder and execute the batch file.

On the end of the compile you should not see any errors.

You should have a ppccrossarm.exe in <fpcsrc>\compiler and some .o and .ppu files on <fpcsrc>\rtl\units\arm-wince

Now copy those files to your Free Pascal installation. The cross compiler ppccrossarm.exe should go to <fpc>\bin\arm-wince and the units to <fpc>\units\arm-wince

Step 4 - Configuration file

Now you need to create fpc.cfg configuration file in <fpc>\bin\arm-wince folder in order to use ppccrossarm.exe easy.

Create empty fpc.cfg file in <fpc>\bin\arm-wince folder and add the following lines to it:

-Twince
-Fu<fpc>\rtl\units\arm-wince
-XParm-wince-
-FDC:\Programas\arm

Remember to substitute the paths with the ones on your system.

Finally add <fpc>\bin\arm-wince to your PATH variable.

Compiling a Test Project

You compiled the compiler! Now, what can I do with it? This is a tutorial to create a hello world like software with your new compiler.

Step 1 - Installing and Configuring the Emulator

You will need a Windows CE Emulator configured for ActiveSync. The ActiveSync is necessary to install PocketCMD, a command line tool to run our hello world software.

Download the free Pocket PC device emulator from Microsoft. It emulates ARM CPU. It is beta currently, but stable. http://msdn.microsoft.com/mobility/windowsmobile/downloads/emulatorpreview/default.aspx

There is a tutorial on how to set up the Emulator for ActiveSync here.

Step 2 - Installing the command line

Download and install PocketCMD by SymbolicTools. Get it here

Check the "WinCE port notes" section bellow for more details on command lines on Pocket PC.

Step 3 - Compiling

A example file to compile:

program test;

{$apptype console}

var
  Str: string;
begin
  WriteLn('Software Developed with:');
  WriteLn('The Free Pascal Compiler');
  WriteLn('');
  WriteLn('Please, enter your name:');
  ReadLn(Str);
  WriteLn('Your name is: ' + Str);
end.

Sample command line:

ppcrossarm.exe -Twince -FuC:\Programas\fpc21\rtl\units\a rm-wince -FDC:\Programas\arm -XParm-wince- test.pas

Here is a screenshot of a software created this way.

Documentation

WinCE port notes

  • chdir procedure always produces an error (WinCE does not support setting of current directory).
  • All file/dir paths must be absolute (started with \).
  • WinCE is unicode OS. All string parameters to API calls must be PWideChar.
  • WinCE does not have support for environment strings.
  • WinCE does not have support for console applications by default. But you can install console support by yourself. Please note that FPC creates GUI applications for WinCE target by default. To create console application you should use -WC compiler switch or put {$APPTYPE CONSOLE} directive to source code.
    To enable console in WinCE install one of the following programs:
    • PocketCMD by SymbolicTools. It is recommended solution. Get it here
    • PPC Command Shell from Microsoft Windows Mobile Developer Power Toys. Get it here
      PPC Command Shell have less features than PocketCMD. Also it have some issues. One of them - a new console window is opened even if an application is started from a console command prompt.

Links

Contacts

Write any questions regarding WinCE port to Yury Sidorov