Difference between revisions of "WinCE port"

From Free Pascal wiki
Jump to navigationJump to search
(fixing Building Tutorial)
Line 17: Line 17:
 
'''Step 1''' - Cross binutils
 
'''Step 1''' - Cross binutils
  
These are the basic tools necessary to create arm executables, such as: Linker, Assembler, Ar (Creates smartlinking .a files), make and strip.
+
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.
 
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.
 
Extract them to some dir in the path on your machine.
 
 
We will supose that you extracted the cross binutils to: C:\Programas\arm
 
We will supose that you extracted the cross binutils to: C:\Programas\arm
  
'''Step 2''' - The Compiler
+
'''Step 2''' - Cross compiler
  
Free Pascal is able to compile itself, so we will need to have it installed. It is possible to compile the arm cross compiler with both Free Pascal 2.0.2 (latest stable build) or with a snapshot from the 2.1.x branch. We recomend a snapshot from the 2.1.x branch. You can get snapshots [http://www.de.freepascal.org/lazarus/ here].
+
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.
  
You can get the 2.1 source repository from Subversion: http://www.freepascal.org/develop.html#svn
+
Get the latest 2.1.x source repository from Subversion: http://www.freepascal.org/develop.html#svn
  
We will supose that you are using the compiler available with the Lazarus Snapshot, because this is a good tool to test the upcoming Windows CE widgetset.
+
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 [http://www.de.freepascal.org/lazarus/ here].
  
In this case we will supose that your compiler is located here: C:\Programas\lazarus13\pp\bin\i386-win32
+
In this case we will supose that your Win32 compiler is located here: C:\Programas\lazarus13\pp\bin\i386-win32
  
And you Free Pascal source code is located here: C:\Programas\fpc21
+
And you Free Pascal 2.1.x source code is located here: C:\Programas\fpc21
  
 
'''Step 3''' - The Build process
 
'''Step 3''' - The Build process
  
In order to build the compiler it is necessary to have a correct PATH environment variable and a configured fpc.cfg file.
+
In order to build the compiler it is necessary to have a correct PATH environment variable.
 
 
Now you need to edit your fpc.cfg file to add information about the binutils. The file is located on the same directory as the compiler. In this case: C:\Programas\lazarus13\pp\bin\i386-win32\
 
 
 
Add the following lines to it it´s end:
 
<pre>
 
-FuC:\Programas\fpc21\rtl\units\$FPCTARGET
 
-XParm-wince-
 
-FDC:\Programas\arm
 
</pre>
 
 
 
Remember to substitute the paths with the ones on your system
 
 
 
 
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:
 
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:
  
 
<pre>
 
<pre>
 
PATH=C:\Programas\lazarus13\pp\bin\i386-win32;c:\Programas\arm
 
PATH=C:\Programas\lazarus13\pp\bin\i386-win32;c:\Programas\arm
fpcmake -Tall
 
 
make cycle CPU_TARGET=arm OS_TARGET=wince
 
make cycle CPU_TARGET=arm OS_TARGET=wince
 
</pre>
 
</pre>
  
Put this file on C:\Programas\fpc\compiler , open the Windows command line, go to this directory and execute the batch file.
+
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 it will give some errors:
 
 
 
<pre>
 
/cygdrive/c/Programas/arm/arm-wince-ld: unrecognised emulation mode: i386pe
 
Supported emulations: armpe
 
pp.pas(213,1) Error: Error while linking
 
make[1]: *** [ppc.exe] Error 1
 
make[1]: Leaving directory `C:/Programas/fpc21/compiler'
 
make: *** [cycle] Error 2
 
</pre>
 
  
This is not a problem! Just check that you have a ppccrossarm.exe in <fpcsrc>\compiler and some .o and .ppu files on <fpcstr>\rtl\units\arm-wince
+
On the end of the compile you should not see any errors.  
  
If you have these files the process was successfull!
+
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 compiler should go to <fpc>\bin\i386-win32 and the units to <fpc>\units\arm-wince
+
Now copy those files to your Free Pascal installation. The cross compiler ppccrossarm.exe  should go to <fpc>\bin\i386-win32 and the units to <fpc>\units\arm-wince
  
 
== Compiling a Test Project ==
 
== Compiling a Test Project ==

Revision as of 11:45, 14 February 2006

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\i386-win32 and the units to <fpc>\units\arm-wince

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