Create Lazarus share library in android lazarus / 43-Android ---------------------------------------------------------------------- aradeonas · 2015-11-11 16:44 Hi, How can I make a share library (.so) in Lazarus that do a simple task like sum two number and can be used in android? Any one has an example or tutorial? ---------------------------------------------------------------------- Jurassic Pork · 2015-11-11 22:38 hello, i don't know if the following code works under android but it works under ubuntu :  example 1 - create the shared library Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library mySumlib; {$mode objfpc}{$H+} uses  Classes; function mySum(int1,int2 :integer): integer; cdecl;begin    result := int1 + int2 ;end; exports  mySum;end. compile :  a .so is created. create a project to use the shared lib (my example use statically load library but you can use also l library dynamically load). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tst_Sharedlib; {$mode objfpc}{$H+} uses  Classes,sysutils; function mySum(int1,int2: integer): integer; external 'mysumlib'; begin  writeln('sharedlib test');  writeln('the result of 323 + 593 is : ' + inttoStr(mySum(323,593)));end. don't forget the option : Compiler Options /Compilation and Linking Enable setting: "Pass options to linker with "-k", delimiter is space" with this option   : -R ./    to indicate where is the library (path). Compile and run result   :  Quotesharedlib test the result of 323 + 593 is : 916 ---------------------------------------------------------------------- balazsszekely · 2015-11-12 09:36 In case you want to load it dynamically:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses dynlibs, LCLType; type  TmySum = function(Int1, Int2: Integer): Integer; cdecl; var  LibHandle: TLibHandle = NilHandle;  mySum: TmySum = nil;  function Load(const ALibName, AFuncName: string): Boolean;var FarProc: TFarProc;begin  Result := False;  LibHandle := LoadLibrary(ALibName);  if LibHandle <> NilHandle then  begin    FarProc := GetProcedureAddress(LibHandle, AFuncName);    if FarProc <> nil then    begin      MySum := TMySum(FarProc);      Result := mySum <> nil;    end;  end;end;                  function UnLoad: Boolean;begin  Result := True;  if LibHandle <> NilHandle then  begin    Result := UnloadLibrary(LibHandle);    if Result then    begin      LibHandle := NilHandle;      mySum := nil;   end;  end;end; Usage: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var LibName: string;begin  LibName := ExtractFilePath(ParamStr(0)) + 'mySumlib.' + SharedSuffix; //you can change the path if necessary  if Load(LibName, 'mySum') then    ShowMessage(IntToStr(mySum(3, 4)));  UnLoad;end; ---------------------------------------------------------------------- jmpessoa · 2015-11-13 00:09 Hello aradeonas! Here is a simple and complete  "Lamw: Lazarus Android Wizard"  NoGUI project... ref.:  https://od.lk/f/Ml8xMDUyNjY3NDlf ---------------------------------------------------------------------- aradeonas · 2015-11-13 10:23 Hi jmpessoa and thanks. Sadly I cant download it,can you upload this here? ---------------------------------------------------------------------- jmpessoa · 2015-11-13 14:28 Sorry.... See Attachment .... ---------------------------------------------------------------------- aradeonas · 2015-11-13 17:07 Thanks. But one problem is that I cant make the app in Lazarus and I just want to write some stuff in a share library and use it in the Java Android project. ---------------------------------------------------------------------- jmpessoa · 2015-11-13 18:16 Yes, is just about! You can learn from my project. Folder  ..\jni 1. From "*.lpi"  cross-compile settings...  [change according to your system and "build"  to get the ".so" -->  ..\libs\armeabi ] 2. From "*.lpr"  JNI pascal side 3. From "*.java"  how to call/use your lib NOTE:  you need a Lazarus prepared to cross-compile... For windows there is  "Laz4Android": ref:  http://sourceforge.net/projects/laz4android/files/?source=navbar FPC: 3.0.0 rc2 (win32/arm-android/i386-android/jvm-android) Lazarus:1.4.4 Android NDK: r10e (arm-linux-androideabi-4.9 + x86-4.9)