Recent

Author Topic: Loading .so Files in Program  (Read 14787 times)

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #15 on: August 12, 2015, 03:40:35 pm »
If ZEOS DBO component can run on ARM you should be able to use dynlib on ARM too!!!

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7504
Re: Loading .so Files in Program
« Reply #16 on: August 12, 2015, 04:00:36 pm »
Try

export LD_LIBRARY_PATH=/path/to/dll;%LD_LIBRARYPATH%

and then run your library.

Under *nix there is a list of paths that may contain libraries. (usually /lib, /usr/lib and /usr/local/lib).

The list is maintained via the ldconfig command, but an user specific  LD_LIBRARY_PATH can overrides/add to it.

PatrickS

  • New member
  • *
  • Posts: 9
Re: Loading .so Files in Program
« Reply #17 on: August 14, 2015, 12:47:59 pm »
Hallo,

I tried the command with 
export LD_LIBRARY_PATH=/path/to/dll;%LD_LIBRARYPATH%

but still nothing happens. Still not possible to load self created lib (created with pascal) in programm. all other libs work, also libs which are created with C.

It MUST be an error of the compiler because everything is running, but not under armhf!

Did somebody checked ut the examles which i send with before under armhf?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7504
Re: Loading .so Files in Program
« Reply #18 on: August 14, 2015, 01:56:06 pm »
That should be a :  btw, not a ;   my bad.

No I haven't investigated, I don't have the time to mimick the circumstances atm, and in general avoid creating shared libs on *nix, so it is not really my area of expertise.

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #19 on: August 14, 2015, 03:34:04 pm »
That should be a :  btw, not a ;   my bad.

No I haven't investigated, I don't have the time to mimick the circumstances atm, and in general avoid creating shared libs on *nix, so it is not really my area of expertise.
I didn't have the time to test your code too. I'm writing this during my job time and I'm far behind schedule, thus isn't much what I can do ATM and near future.

But we use libraries (with dynamic and static linking and currently I'm moving everything to the dynamic way) on Linux and windows. We are connecting to hardware and third-party servers trhough our own libraries and everything is working smoothly with same code on both OSes and without using IFDEFs.

AFAICS it can be caused by:
  1- something silly, like file name / path miss spelled.
  2- something more serioius like a difference on ARM's Linux which could cause a problem with FPC's dynlib.pas (least probable).
You can check point 2 easily by trying to run an app with ZEOS which uses dynlib to connect to DB. Lets say if youinstall SQLite3 on your ARM device and try to open or create a new SQLite DB using TZConnection. If no error then everything's great. you also can avoid instaling SQLite-3 and copy the library to your test proyect folder an try the following code :
Put a TZConnection, a TOpenDialog, and a TButton on a form and a put this code inside the TButton.OnClick event:
Code: [Select]
   if OpenDialog1.Execute then begin
      ZConnection1.LibraryLocation := OpenDialog1.FileName;
      ZConnection1.Database := Application.Location+'test.db';
      ZConnection1.Protocl := 'sqlite-3';
      ZConnection1.Connect;
   end;

Execute it and select the sqlite 3 library file from the dialog and press OK button. if everything is fine a new file with the name "test.db" will appear in the same folder as the binary is.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7504
Re: Loading .so Files in Program
« Reply #20 on: August 14, 2015, 03:53:28 pm »
Another thing to try is passing an absolute path.

But I avoided pascal generated shared libs, and installed other libs in their directories and registered any new library directories with "ldconfig".

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #21 on: August 14, 2015, 10:41:03 pm »
Another thing to try is passing an absolute path.

But I avoided pascal generated shared libs, and installed other libs in their directories and registered any new library directories with "ldconfig".
And that's the right way!!

PatrickS

  • New member
  • *
  • Posts: 9
Re: Loading .so Files in Program
« Reply #22 on: August 19, 2015, 02:21:31 pm »
I tried all of this but the problem still exists....

Probably an error of the compiler. Please can anybody verify this problem before a bug report will be generated.

Architecure is armhf compiler 2.6.4  (debian wheezy) ( Pakages is in backports)
also with the compiler 3.1.1 this error occurs.

Best regards
Patrick
« Last Edit: August 19, 2015, 02:24:40 pm by PatrickS »

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #23 on: August 20, 2015, 02:31:19 pm »
Now I'm on Linux trying your code but I cant compile the library because a weird error (Error: Illegal parameter: -WR). It's not in your code but in the project config, I think. I never had this error compiling and I can't find that parameter....

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #24 on: August 20, 2015, 03:06:48 pm »
Now I'm on Linux trying your code but I cant compile the library because a weird error (Error: Illegal parameter: -WR). It's not in your code but in the project config, I think. I never had this error compiling and I can't find that parameter....


My bad, I found it.

The attached example runs on my Ubuntu 10.04, compiled using FPC 2.6.2 and an old Lazarus.

No need to register anything to OS just compile the library, the tester project and run it!!

Is weird that I had to do this
Code: [Select]
const
   PROJECT1_DLL_LIBRARY_NAME = {$IFDEF UNIX}'lib'+{$ENDIF}'project1_dll.' + SharedSuffix;
   PROJECT1_DLL_LIBRARY_PROC_PATRICK_ADD = 'Patrick_Add';
although I was telling you it wasn't necessary (to add the prefix and the suffix). My projects do not have it!!! %) %) %) %)

If you keep having problems, then I think you should report it to the bug tracker.

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Loading .so Files in Program
« Reply #25 on: August 20, 2015, 03:08:45 pm »
Sorry, forgot to attach the files.... :-[ :-[ :-[ :-[ :-[

PatrickS

  • New member
  • *
  • Posts: 9
Re: Loading .so Files in Program
« Reply #26 on: August 21, 2015, 03:00:58 pm »
Thank you for yout try.

Here is also a link from a forum, which also handles with this topic:
http://free-pascal-general.1045716.n5.nabble.com/shared-library-on-arm-linux-raspberry-pi-td5719653.html


I already started a ticket in Bugtracker of fpc. 28545