【问题标题】:Using native C static libraries in Delphi Firemonkey iOS development在 Delphi Firemonkey iOS 开发中使用原生 C 静态库
【发布时间】:2012-04-13 06:37:55
【问题描述】:

我对使用 Firemonkey 制作 iOS 应用程序很感兴趣。我想在这个应用程序中使用几个本机 C 库。我知道 iOS 不允许动态链接库,但是有没有办法在这个 firemonkey iOS 应用中使用静态库?

【问题讨论】:

  • FPC 文档对此事有什么要说的?
  • 看来Delphi一般不能创建或使用静态库。

标签: ios delphi static-libraries firemonkey


【解决方案1】:

是的,您可以使用 C 静态库通过 xcode 与 Firemonkey iOS 应用程序链接。 我是在 RADStudio X2 之外使用 Xcode 完成的。使用 RADStudio,我生成了 xcode 项目。在 Mac 上,我打开了 xcode 项目并添加了:

function C_func(double :x):double; cdecl; external;

{$linklib my_c_lib.a}

我在 xcode 中创建了一个静态库项目(名为 my_c_lib),其中包含一个 C 文件:

double C_func(double x)
{
    return x+2.5;
}

我想你可以以同样的方式使用已经编译的静态库。

【讨论】:

  • 有一篇关于类似问题的帖子here
【解决方案2】:

这是我制作的一个 iOS 应用程序: Unit1.pas 由 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.

而C文件tst1.c为:

#include <stdio.h>
#include <math.h>

double tst_function(double x)
{
    return sin(x)+0.25;
}

【讨论】:

    猜你喜欢
    • 2016-01-12
    • 2013-05-07
    • 2015-12-16
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多