Sign in Join
Wiki copytemporary

Free Pascal on OSv: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# OSv
22
33OSv is an operating system based on Linux optimized for the cloud. [Official page](http://osv.io/) It runs a single application together with a small kernel and all needed libraries in a virtual machine. That means to run OSv applications you need to install a hypervisor such as QEMU/KVM or VirtualBox.
44
55# Installation
66
77## Install OSv on Linux
88
99This worked on 3rd Mar 2015 on Ubuntu 14.10 and on 3rd Sep 2016 on Ubuntu 16.04:
1010
1111Please read <http://osv.io/run-locally/>. Especially about the "Data collection".
1212
1313Downloading capstan to ~/bin/capstan:
1414
15-`curl `[`https://raw.githubusercontent.com/cloudius-systems/capstan/master/scripts/download`](https://raw.githubusercontent.com/cloudius-systems/capstan/master/scripts/download)` | bash`
15+```text
16+curl https://raw.githubusercontent.com/cloudius-systems/capstan/master/scripts/download | bash
17+```
1618
1719Install needed qemu-kvm (VirtualBox is also possible, but not handled in this document)
1820
19-`sudo apt-get install qemu-kvm`
21+```text
22+sudo apt-get install qemu-kvm
23+```
2024
2125# Building an instance with capstan
2226
2327Capstan takes a basic image and adds your libraries to create a VM image. It then starts the VM and runs the 'main' function of your library. At the moment only Linux/amd64 dynamic libraries with PIC are supported.
2428
2529## Capstanfile
2630
2731Capstan needs a config file named *Capstanfile*. Read [here](https://github.com/cloudius-systems/capstan/blob/master/Documentation/Capstanfile.md) for details.
2832
2933Create a directory for the example. For instance ~/osv_fpc_test.
3034
3135Here is an example config for a hello world program (~/osv_fpc_test/Capstanfile):
3236
3337 # Name of the base image. Capstan will download this automatically from Capstan repository.
3438 base: cloudius/osv-base
3539
3640 # The command line passed to OSv to start up the application.
3741 cmdline: /tools/hello.so
3842
3943 # The command used to build the application.
4044 build: ./compile.sh
4145
4246 # List of files that are included in the generated image.
4347 files:
4448 /tools/hello.so: hello.so
4549
4650## Pascal Library
4751
4852The small Linux kernel does not support all syscalls needed by the default FPC Linux System unit.
4953
5054See here for some details what OSv does not support: <https://github.com/cloudius-systems/osv/wiki/Porting-native-applications-to-OSv>
5155
5256You need to build the System unit using Libc (tested with fpc trunk revision 34418):
5357
54-`cd fpc_src_3.1.1`\
55-`make clean all OPT='-dFPC_USE_LIBC -Fl/usr/lib/gcc/x86_64-linux-gnu/5'`\
56-`sudo make install INSTALL_PREFIX=/usr`
58+```text
59+cd fpc_src_3.1.1
60+make clean all OPT='-dFPC_USE_LIBC -Fl/usr/lib/gcc/x86_64-linux-gnu/5'
61+sudo make install INSTALL_PREFIX=/usr
62+```
5763
5864## hello.pas
5965
6066``` pascal
6167library hello;
6268
6369// start function for OSv
6470function main: longint; cdecl;
6571begin
6672 Writeln('It works!');
6773 main:=0;
6874end;
6975
7076exports main name 'main'; // OSv searches for 'main' in the library
7177
7278end.
7379```
7480
7581Here is the *~/osv_fpc_test/compile.sh*:
7682
7783 #!/bin/bash
7884 # create a dynamically linked library hello.so
7985 /usr/lib/fpc/3.1.1/ppcx64 -fPIC -XD -Xc -gw2 -ohello.so hello.pas
8086
8187## Building
8288
8389**Note**: The first time you build, capstan will download the base VM image "cloudius/osv-base" (~/.capstan/).
8490
8591 []$ cd ~/osv_fpc_test
8692 []$ ~/bin/capstan build
8793 Building osv...
8894 Uploading files...
8995 1 / 1 [===================================] 100.00 %
9096
9197## Running
9298
9399 []$ ~/bin/capstan run
94100 Created instance: helloworld
95101 OSv v0.18
96102 eth0: 192.168.122.15
97103 It works!
98104
99105# Pascal Library without using the System unit
100106
101107As demonstration here is a library, that does not call the system unit (works the normal FPC system unit):
102108
103109## hello.pas
104110
105111Here is the *~/osv_fpc_test/hello.pas*:
106112
107113``` pascal
108114library hello;
109115
110116uses
111117 unixtype;
112118
113119// use the C function 'write'
114120function CWrite(fd : cInt; buf:pChar; nbytes : unixtype.TSize): TSsize; external name 'write';
115121
116122// start function for OSv
117123function main: longint; cdecl;
118124const
119125 MyText: PChar = 'It works!'#10;
120126begin
121127 CWrite(StdOutputHandle,MyText,strlen(MyText));
122128 main:=0;
123129end;
124130
125131exports main name 'main'; // OSv searches for 'main' in the library
126132
127133end.
128134```
129135
130136## Compile a library that does not call the system init
131137
132138Here is the *~/osv_fpc_test/compile.sh*:
133139
134140 #!/bin/bash
135141
136142 # compile without linking, create a dynamically linked library hello.so
137143 fpc -fPIC -XD -Xc -g -s -ohello.so hello.pas
138144 # link without -init FPC_SHARED_LIB_START -fini FPC_LIB_EXIT
139145 /usr/bin/ld -b elf64-x86-64 -m elf_x86_64 -soname hello.so -shared -L. -o hello.so link.res
140146
141147## Building
142148
143149**Note**: The first time you build, capstan will download the base VM image "cloudius/osv-base" (~/.capstan/).
144150
145151 []$ cd ~/osv_fpc_test
146152 []$ ~/bin/capstan build
147153 Building osv...
148154 Uploading files...
149155 1 / 1 [===================================] 100.00 %
150156
151157## Running
152158
153159 []$ cd ~/osv_fpc_test
154160 []$ ~/bin/capstan run
155161 Created instance: osv
156162 OSv v0.18
157163 eth0: 192.168.122.15
158164 It works!
159165
160166---
161167*From the Free Pascal wiki, page "Free Pascal on OSv", as it stood on 2020-02-16 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
162168Category: Linux

Back to history