ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.22k stars 141 forks source link

What would be an elegant way to load a .so-file from a dynamic path #727

Open nomelif opened 3 years ago

nomelif commented 3 years ago

(I am sorry if a GH issue is not the best place to ask. Where should I rather be asking this?)

I am trying to build a program that I am trying to distribute as an AppImage. Said program depends on an .so -file generated in part by chibi-ffi. As the exact folder where the .so file lands when the AppImage is mounted is fairly unpredictable (and as I also wish to run the unpackaged thing with make run, thus avoiding the time spent rebuilding the AppImage when developing.), I am currently cd-ing into the folder with the .so-file and using something to the tune of (include-shared "./my-lib") to include it.

However that forces me to change the working directory into a random folder within a hidden folder within /tmp, which I find confusing for the user. Ideally, I would like to have the AppImage's AppRun-file (which is a shell script that sets the environment up) and my Makefile set up an environment variable to the tune of MYAPP_LIB which would point to the where my .so-file lives. Then I would do something like

(include-shared (string-append (get-environment-variable "MYAPP_LIB") "/my-lib"))

However, include-shared is a macro and doesn't seem to play nice with this approach. The wiki talks about load, but it seems to only load the symbols and not actually define the functions themselves (a feature of include-shared I am rather fond of).

Is there a built-in mechanism to solve this problem in an elegant way?

ashinn commented 3 years ago

For general questions, please ask on the mailing list: chibi-scheme@googlegroups.com

Chibi searches the same module load path for shared libraries as for Scheme code.

You can use add-module-directory' from Scheme orsexp_add_module_directory` from C to set this up prior to loading the module.