Author Topic: compiling an iOS dylib -- am I doing it right?  (Read 3262 times)


  • Full Member
  • ***
  • Posts: 146
  • Pascal dev
compiling an iOS dylib -- am I doing it right?
« on: September 25, 2020, 10:40:52 pm »
I'm building my first library file for iOS, and I'd like to know if I'm doing it right.

Below is what I have done, including source code and compiled dylib.

If anyone can tell me if I'm on the right path, or if I'm doing something wrong, it will be very appreciated!

Here goes:

The library itself contains a few simple functions, for purely testing purposes -- just to see if I can load the library from iOS/Swift code and pass parameters back and forth.

Simplified to the max, the library looks like this:

Code: Pascal  [Select][+][-]
  1. library ios01;
  3. function test1: integer; cdecl;
  4. begin
  5.   result := 1;
  6. end;
  8. exports test1;
  10. end;

Now, to compile the above for iOS I did the following main steps:

* Loaded a Catalina virtual machine on VBox.
* Installed FPC 3.2.0 compiler, sources, and Lazarus for Mac.
* Installed Xcode (version 12)
* Installed MacOS cross iOS compiler
* (I also installed the command line tools, but I'm not sure of what role they play)

To do the actual cross compiling (MacOS -> iOS) I call the following line from a bash file:

Code: Bash  [Select][+][-]
  1. ppca64 ios01.lpr -Paarch64 @fpc_ios.cfg -olibtest.dylib

Where the parameters are:

ppca64 = compile for aarch64
1. ios01.lpr is the above source
2. -Paarch64 indicates I'm building a 64-biy dylib for iOS
3. fpc_ios.cfg is a file that completely overrides the default settings
(usually stored in a fpc.cfg file). See below for the content of the file.
4. the output file name

Here is my fpc_ios.cfg file, which overrides the default:

Code: Bash  [Select][+][-]
  2. # dont use default fpc.cfg, override everything with this file
  3. -n
  5. # my preferred syntax mode, -O1 basic optimizazion, -Xs strip debug info, -v high verbosity
  6. -Mobjfpc
  7. -O1
  8. -Xs
  9. -veiwnvb
  11. # store build units in this folder:
  12. -FUlib/ios/
  14. #darwin use pipes instead of temporary files for assembling
  15. -ap
  17. # Unit system used by compiler -- this is where all the iOS-oriented fpc sources have been installed
  18. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*
  20. # iOS SDK -- this is used by the linker to produce the final dylib file from the compiler units
  21. -XR/Applications/

By doing all of the above I get a 250kb dylib file.

The source code and the dylib file are attached to this message.

As I said, I cannot currently test it by bundling it into a real iPhone app and running it, and that's the first reason for this post: if by any chance you're currently working on an iOS app, could you kindly try to include this library, load it, call "test1", and see if it returns the number 1? This would prove that all the above steps indeed lead to a functioning iOS library! Or vice-versa, if it crashes, I'd like to get some clues to what I'm doing wrong.

And the other reason for this post is to ask you to review the above compiler options, source code, etc. and kindly let me know if what you see is OK, or is it missing something, or something should be changed.

Any feedback and any suggestions will be very appreciated!
manlio mazzon gmail


TinyPortal © 2005-2018