I am interested in using Firemonkey for producing an iOS app. There are several native C libraries I would like to use in this application. I know that iOS does not allow for dynamic link libraries, but is there a way to use static libraries in this firemonkey iOS app?
2
-
What does the FPC documentation have to say on the matter?David Heffernan– David Heffernan2012-04-13 07:26:00 +00:00Commented Apr 13, 2012 at 7:26
-
It seems that Delphi in general cannot create or use static libraries.user1027169– user10271692012-04-13 19:40:16 +00:00Commented Apr 13, 2012 at 19:40
Add a comment
|
2 Answers
Yes, you can use C static libraries to link with Firemonkey iOS appli using xcode. I did it using Xcode outside RADStudio X2. With RADStudio I generated xcode project. On the mac I openned the xcode project and added :
function C_func(double :x):double; cdecl; external;
{$linklib my_c_lib.a}
I created static library project in xcode (named my_c_lib) with one C file containing :
double C_func(double x)
{
return x+2.5;
}
I suppose that in the same manner you can use already compiled static libs.
Here is an iOS application I made: Unit1.pas is generated by XE2:
unit Unit1;
interface
uses
SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
FMX_Dialogs, FMXTee_Engine, FMXTee_Series, FMXTee_Procs, FMXTee_Chart,
FMX_ExtCtrls;
type
TForm1 = class(TForm)
CornerButton1: TCornerButton;
Chart1: TChart;
Series1: TLineSeries;
Label1: TLabel;
procedure CornerButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
x : double; // I added this in Xcode Editor
end;
// I added this declaration
function tst_function(x:double):double;cdecl;external;
var
Form1: TForm1;
implementation
{$R *.lfm}
{$link tst1.o} // I added this
procedure TForm1.CornerButton1Click(Sender: TObject);
var i: integer; x : double;
begin
for i := 1 to 500 do
begin
x:=tst_function(i*3.14/250.0);
Series2.Add(x);
end
end;
end.
and the C file tst1.c is:
#include <stdio.h>
#include <math.h>
double tst_function(double x)
{
return sin(x)+0.25;
}