Recent

Author Topic: [SOLVED] Cannot load library file using LoadLibrary() in Lazarus on Linux  (Read 1026 times)

Codrut1001

  • New Member
  • *
  • Posts: 22
I would like to use the Bass audio library in Lazarus for linux, I have the ".so" files and the units, but when I try to run the application, I get an error.

The error occurs at the LoadLibrary() function.

This is the error:
The file "/build/glibc-BHL3KM/glibc-2.31/elf/dl-error-skeleton.c" was not found.
Do you want to locate it yourself?

I think this may be something with the compiler Itself, as It's not necessarily an error. For some reason, It cannot find a file.

I am using the "dynlibs" unit for the library loading related functions.

Any help would be greatly appreciated! :)
« Last Edit: November 20, 2023, 07:19:29 pm by Codrut1001 »

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #1 on: November 20, 2023, 05:21:18 pm »
Where did you put the libbass.so file ?

From the BASS documentation:
Quote
Linux version
-------------
The LIBBASS.SO file needs to be in the OS's library search path for it to
be found; simply placing it in the same directory as the executable won't
necessarily work as it does on other platforms. The BASS libraries should
also not be placed in the standard library directories to avoid version
conflicts. To meet those competing requirements, a wrapper script could be
used to set the "LD_LIBRARY_PATH" environment variable before loading the
executable. Another option is to set the "rpath" in the executable to tell
it where to look for libraries, which is what the example makefiles do.

When building for multiple architectures, it is possible to simply try linking
with all LIBBASS.SO versions, and the linker will use the appropriate one and
ignore the others.

Codrut1001

  • New Member
  • *
  • Posts: 22
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #2 on: November 20, 2023, 05:58:35 pm »
Where did you put the libbass.so file ?

I placed the libbass.so file in the same directory as the executable. I also tried placing it in "/usr/bin", with the result being the same.

Also, using the LoadLibrary() with any string still opens the same dialog, with the missing "dl-error-skeleton.c" file, so I still believe Lazarus is not configured properly.
« Last Edit: November 20, 2023, 06:12:03 pm by Codrut1001 »

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #3 on: November 20, 2023, 06:09:38 pm »
I placed the libbass.so file in the same directory as the executable. I also tried placing it in "/usr/bin", with the result being the same.
Well, according to the doc I quoted that is wrong.
Is /usr/bin in your OS path?

You could also set the rpath.
Read the quoted part.

Also, using the LoadLibrary() with any string still opens the same dialog, with the missing "dl-error-skeleton.c" file, so I still believe Lazarus is not configured properly.
It's not Lazarus.

Could be that the .so can be found (but read above) but that there is something missing in your OS (the correct glibc libs for example).

But first try the correct lib location or set it correctly.

Codrut1001

  • New Member
  • *
  • Posts: 22
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #4 on: November 20, 2023, 06:45:53 pm »
It's not Lazarus.

Could be that the .so can be found (but read above) but that there is something missing in your OS (the correct glibc libs for example).

But first try the correct lib location or set it correctly.

When I have a break-point on this line, the error appears, when I don't, the error does not appear, but FBassDLL is 0
FBassDLL := LoadLibrary(PChar(BassDLL));

"/usr/bin/" is indeed in $PATH

Also, this (https://forum.lazarus.freepascal.org/index.php?topic=45274.0l) question on the form also confirms that It's a debugger issue.

But FBassDLL is 0 after LoadLibrary(), and since the debugger is unable to provide a error message, I can't load the library. :/

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #5 on: November 20, 2023, 06:51:42 pm »
LoadLibrary just takes a unicodestring or rawbytestring.
https://www.freepascal.org/docs-html/rtl/dynlibs/loadlibrary.html

So you can just do
Code: Pascal  [Select][+][-]
  1. FBassDLL := LoadLibrary(BassDLL);

I'm not sure if your pchar gets cyber automatically back to a string.
What happens to FBassDLL if you do that.
(BassDLL should only contain the filename, not the path)


Codrut1001

  • New Member
  • *
  • Posts: 22
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #6 on: November 20, 2023, 06:57:06 pm »
So you can just do
Code: Pascal  [Select][+][-]
  1. FBassDLL := LoadLibrary(BassDLL);

FBassDLL is still 0. I also tried SafeLoadLibrary(), with the same result.

rvk

  • Hero Member
  • *****
  • Posts: 6572
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #7 on: November 20, 2023, 07:05:51 pm »
What does GetLoadErrorStr return after LoadLibrary?

https://www.freepascal.org/docs-html/rtl/dynlibs/getloaderrorstr.html

Codrut1001

  • New Member
  • *
  • Posts: 22
Re: Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #8 on: November 20, 2023, 07:18:14 pm »
What does GetLoadErrorStr return after LoadLibrary?

https://www.freepascal.org/docs-html/rtl/dynlibs/getloaderrorstr.html

The file could not be found.
From this, I was able to figure out that the file "libbass.so" needed to be placed in "/usr/lib", instead of "/usr/bin", I didn't check that properly since I have not developed many apps for linux before.

Also, as a side note, in case anyone else stumbles upon this, on linux the BASS_UNICODE flag should not be used!

Thank you so much!
« Last Edit: November 20, 2023, 07:19:58 pm by Codrut1001 »

Чебурашка

  • Hero Member
  • *****
  • Posts: 586
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: [SOLVED] Cannot load library file using LoadLibrary() in Lazarus on Linux
« Reply #9 on: November 20, 2023, 09:44:14 pm »
The default is to call LoadLibrary supplying the library name only, and that requires the library to be in a valid search location (and pay attention that some distributions add version to library name libABC.so.1.2.3, in such a case a symlink libABC.so -> libABC.so.1.2.3 helps).

Another way is to call your program with a suitable LD_LIBRARY_PATH env variable, for example if the library is in current directory

> LD_LIBRARY_PATH=. ./myprogram

will work.
Another way is to supply to LoadLibrary the library file full path:

LoadLibrary('/usr/local/mylibs/libABC.so');

in the case the search mechanism will not be applied and only the absolute path is used.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018