Page 1 of 1

How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 9:08 am
by Martin Verlaan
For my latest project I used the import-command to load the BASS audio library. However, this appears to cause problems on other computers because BASS is in a subfolder of my program and Import also on other computers refers to the absolute location of the BASS-folder computer on which I compiled the program.

Someone on this forum advised me to use OpenLibrary(). Is it true that I can use this command for a relative folder and does it still work in Linux? I spent a day trying to figure out how OpenLibrary works, but I still can't figure out how to import functions from a .so file with it. Would anyone be kind enough to give a small example or know another solution to my problem?

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 2:27 pm
by mk-soft
Example with SDL
Link: https://www.purebasic.fr/english/viewto ... 15#p618215

Works with path to lib

But ...
If the BASS library has been properly installed under Linux, there should be no problems with importing.
The library must also be in the correct folder under linux so that it can always be found.

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 2:59 pm
by Martin Verlaan
Hi mk-soft, thanks for this clear example :!:
mk-soft wrote: Fri Mar 29, 2024 2:27 pm But ...
If the BASS library has been properly installed under Linux, there should be no problems with importing.
The library must also be in the correct folder under linux so that it can always be found.
The idea was that my program should work immediately, without copying BASS files to /usr/lib/
That's why I had put BASS into a subfolder of my program, but maybe that is not the best idea?

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 3:04 pm
by mk-soft
There are also rules under Linux as to where something has to be located.
It only works with the effort via LoadLibrary with path specification.

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 5:39 pm
by Fred
How do you import the bass library in your code ?

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 6:56 pm
by Martin Verlaan
Like this:

Code: Select all

IncludeFile "pb_include/bass/linux/bass.pbi"

bass.pbi:

Code: Select all

;... 
Import "../../../assets/bass/linux/libbass.so" 
  BASS_SetConfig.l(option.l,value.l)
  BASS_GetConfig.l(option.l)
 ;and so on...
EndImport

And I solved the problem in bass.pbi with:

Code: Select all

Lib = OpenLibrary(#PB_Any, "assets/bass/linux/libbass.so")

Re: How to use OpenLibrary() with Linux

Posted: Fri Mar 29, 2024 7:04 pm
by Fred
If bass is installed, you should use only ImportC "-lbass" and it should work everywhere