Recent

Author Topic: [solved] Using .so libraries on Linux-arm  (Read 5413 times)

DelphiDinosaur

  • New Member
  • *
  • Posts: 15
[solved] Using .so libraries on Linux-arm
« on: December 01, 2021, 05:55:43 pm »
After some time, I have FPC v3.2.2 and Lazarus 1.8.4 running on a Variscite arm. I can compile and run terminal apps quite happily.

I'm having trouble loading libraries. The attached code works fine on a Linux desktop PC (FPC 3.2.0 & Laz 2.0.12). However, the LoadLibrary function always returns 0 on the same code compiled on the arm.

Using nm -D on the .so lists the exported function on the arm compiled code.

I've used the LoadLibrary function for years on Delphi 6 and XE3 so don't believe there's anything fundamentally wrong with the code. I suspect it's a magic rune in Linux that needs setting.

Any suggestions?

« Last Edit: December 02, 2021, 12:13:30 pm by DelphiDinosaur »

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Using .so libraries on Linux-arm
« Reply #1 on: December 01, 2021, 06:43:37 pm »
Attached is my own library loader, which you might find useful as a known-working example. It underpins the code at e.g. https://github.com/MarkMLl/asound

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Using .so libraries on Linux-arm
« Reply #2 on: December 02, 2021, 09:18:58 am »
I'm having trouble loading libraries. The attached code works fine on a Linux desktop PC (FPC 3.2.0 & Laz 2.0.12). However, the LoadLibrary function always returns 0 on the same code compiled on the arm.

What does GetLoadErrorStr return? What options did you use to compile both the program and the library?

DelphiDinosaur

  • New Member
  • *
  • Posts: 15
Re: Using .so libraries on Linux-arm
« Reply #3 on: December 02, 2021, 11:54:27 am »
What does GetLoadErrorStr return? What options did you use to compile both the program and the library?

GetLoadErrorStr returns "can't open shared object file: No such file or directory", and includes the exact path to the .so (path case matches). The earlier line checking FileExists finds the file.

The same code works with a third party .so saved in the same location so I'm confident it's not the calling program that's the problem.

The library file is compiled with the standard settings when Lazarus starts a new Library project. Any suggestions as to what may need changing?

DD.

DelphiDinosaur

  • New Member
  • *
  • Posts: 15
Re: Using .so libraries on Linux-arm
« Reply #4 on: December 02, 2021, 12:12:15 pm »
Found the answer on Stack Overflow.

Added initc to the uses section was all that was needed.

Seemingly, cmem or LCL may also work but I haven't tried them.

Thanks for your time if you looked at this.

DD.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Using .so libraries on Linux-arm
« Reply #5 on: December 02, 2021, 12:53:49 pm »
Found the answer on Stack Overflow.

Added initc to the uses section was all that was needed.

Seemingly, cmem or LCL may also work but I haven't tried them.

Usually cmem right at the start of the uses list, followed if necessary by heaptrc, then by cthreads etc.

There's another gotcha with at least some versions of libusb, discussed and worked around in the example I posted.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018