Where to put SO files?

BlitzMax Forums/BlitzMax Programming/Where to put SO files?

JoshK(Posted April) [#1]
I have a couple of SO libraries I need BlitzMax to link to, and I can't find where to put the files. I copied them to /lib, /lib/i386-linux-gnu, /lib32, /lib64, /usr/lib, /usr/lib32, /usr/lib/i386-linux-gnu, and BlitzMax still says "/usr/bin/ld: cannot find -lsteam_api".

Where do I put these files?


dawlane(Posted April) [#2]
what's the file name of the so file?


JoshK(Posted April) [#3]
libsteam_api.so
libopenvr_api.so
Import "-lopenvr_api"
Import "-lsteam_api"



dawlane(Posted April) [#4]
And the file is definitely not a link? Try executing ldconfig as sudo to rebuild the library cache.


skidracer(Posted April) [#5]
If you don't want to use Import "-Lblah" to set a lib path you could try copying the .so to BlitzMax/lib.


grable(Posted April) [#6]
GCC handles linking directly do dynamic libs, just like archives. But BCC and BMK wont allow it, so you can rename *.dll/*.so to *.a and Import it. Hackish but it works ;)
The changes to BCC and BMK are pretty minor too, a single line in both of them hehe. Maybe il send a patch someday...


dawlane(Posted April) [#7]
There are a number of ways to handle shared libraries in Linux.
1) For system-wide. Place the shared library in one of the system search paths.

2) Add an entry to /etc/ld.conf.d for the exact path to the libraries.

3) Distribution with your application. This requires setting rpath in the application binary.

You may have to run ldconfig for the first one, but the second one requires ldconfig to be run. And the third one requires a bit of knowledge.

The renaming of file extensions in not recommend. Though creation of a link with a different name would work.


grable(Posted April) [#8]
The renaming of file extensions in not recommend. Though creation of a link with a different name would work.
Yeah, its a hack. But it works on windows, since DLLs have a builtin name (usually) which it uses instead of the renamed one. Dunno if the same is true for linux though...
But what i tend to do instead is use dlltool (mingw only?) to create an archive that links to the DLL for me and import that.


JoshK(Posted April) [#9]
The BlitzMax/lib folder works the best. However, you still have to have an .sh file to launch the app that contains this:
export LD_LIBRARY_PATH=".:${LD_LIBRARY_PATH}"
exec "./ExeFileName" "$@"


I don't think the BlitzMax IDE will load .so files from the same folder as the executable when it launches a program. I suggest that it should, since this would solve a lot of problems.


skidracer(Posted April) [#10]
There are some extra linker flags needed i think. In theory they could be added from main app.

from current bmk_util.bmx:

?Linux

	cmd="g++"
	cmd:+" -m32 -g -pthread"
	cmd:+" -o "+CQuote( path )
	cmd:+" "+CQuote( tmpfile )
	cmd:+" -Wl,-rpath='$ORIGIN'"



Going by this mention of $$ORIGIN and this of XORIGIN I suspect bmk's use of $ORIGIN is not working as intended.