How to use OpenLibrary() with Linux

Linux specific forum
Martin Verlaan
Enthusiast
Enthusiast
Posts: 134
Joined: Sun Apr 01, 2018 11:26 am
Location: Netherlands
Contact:

How to use OpenLibrary() with Linux

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to use OpenLibrary() with Linux

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Martin Verlaan
Enthusiast
Enthusiast
Posts: 134
Joined: Sun Apr 01, 2018 11:26 am
Location: Netherlands
Contact:

Re: How to use OpenLibrary() with Linux

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to use OpenLibrary() with Linux

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How to use OpenLibrary() with Linux

Post by Fred »

How do you import the bass library in your code ?
Martin Verlaan
Enthusiast
Enthusiast
Posts: 134
Joined: Sun Apr 01, 2018 11:26 am
Location: Netherlands
Contact:

Re: How to use OpenLibrary() with Linux

Post 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")
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How to use OpenLibrary() with Linux

Post by Fred »

If bass is installed, you should use only ImportC "-lbass" and it should work everywhere
Post Reply