user1027169
user1027169

Reputation: 2887

Using native C static libraries in Delphi Firemonkey iOS development

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?

Upvotes: 1

Views: 2696

Answers (2)

Yazou
Yazou

Reputation: 206

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;
}

Upvotes: 1

Yazou
Yazou

Reputation: 206

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.

Upvotes: 2

Related Questions