Forum > iPhone/iPad

compiling an iOS dylib -- am I doing it right?

(1/1)

Manlio:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---library ios01; function test1: integer; cdecl;begin  result := 1;end; exports test1; 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- # dont use default fpc.cfg, override everything with this file-n # my preferred syntax mode, -O1 basic optimizazion, -Xs strip debug info, -v high verbosity-Mobjfpc-O1-Xs-veiwnvb # store build units in this folder:-FUlib/ios/ #darwin use pipes instead of temporary files for assembling-ap # Unit system used by compiler -- this is where all the iOS-oriented fpc sources have been installed-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/* # iOS SDK -- this is used by the linker to produce the final dylib file from the compiler units-XR/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk  
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!

joesyuan:
Have you test it ok?

Navigation

[0] Message Index

Go to full version