动态加载的delphi XE7 firemonkey android共享对象/库-模板 [英] delphi XE7 firemonkey android shared object / library to be dynamically loaded - template

查看:137
本文介绍了动态加载的delphi XE7 firemonkey android共享对象/库-模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个模板来创建一个.so文件,该文件可以由另一个delphi ape文件加载-我曾尝试启动一个空白的fire monkey项目并将程序更改为库并进行构建,但是它生成的.so文件不会成功。在另一个delphi项目中加载dlopen。我读过在其他开发环境中有一个图书馆设置。我想更重要的是,有一个用火猴构建的.so库示例-我发现了没有火猴的裸露链接,但它只使用了jni而不是androidapi.jni-谢谢

Is there a template to create a .so file that can be loaded by another delphi ape file - I have tried starting a blank fire monkey project and changing program to library and build it but the .so file that it produces won't load with dlopen within another delphi project. I have read that in other development environments there is a islibrary setting. I guess more to the point is there an example .so library built with fire monkey - I have found the bare bones link without fire monkey but it uses just jni not androidapi.jni - thanks

推荐答案

以下代码可能会有用。

//-- Code for libMylib.so (MyLib.dproj) --- 

    library MyLib; 
//    uses  SysUtils;


    function GetSum(a, b: integer ) : integer; cdecl; 
    begin 
      Result := a + b; 
    end;

    exports

    GetSum        name 'GetSum'; 

    begin 
    end. 

    //-- Code for using libMylib.so (TestMyLib.dproj) --- 

    var 
    DocDir, LibFN: string; 
    GetSum: function(a, b: integer ) : integer; cdecl; 
    hLib: HMODULE; 

    begin 
      DocDir := IncludeTrailingPathDelimiter(System.IOUtils.TPath.GetLibrary`enter code here`Path);
      LibFN:=DocDir + 'libMyLib.so';
      hLib := LoadLibrary(LibFN); //ERROR (Segmentation fault (11)) 
      if hLib<>0 then 
      begin 
        GetSum := GetProcAddress(hLib, 'GetSum');//It works
        ShowMessage(IntToStr(GetSum(3, 8)));//It works 
      end; 
    end; 

PS:必须将已编译的libMyLib.so文件添加到TestMyLib.dproj的部署中。

P.S: you must add compiled libMyLib.so file to Deployment of TestMyLib.dproj.

P.S2:执行 LoadLibrary时出现错误,但是可以。

P.S2: it gives an error while executing "LoadLibrary", but it Works.

我找不到一个解。可能与MyLib.dproj的编译器/链接器选项有关。因为当我测试另一个用C ++编译的 .so文件时,调用LoadLibrary不会发生任何问题。

I couldn't find a solution. Probably it is related with compiler/linker options of MyLib.dproj. Because when I test another '.so' file which is compiled with C++, no problem occurs while calling LoadLibrary.

这篇关于动态加载的delphi XE7 firemonkey android共享对象/库-模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆