Want use shared library in D code, but don't have binding?
You can easily write it yourself with ssll!
Example:
modulemysharedlib;
import ssll;
mixinSSLL_INIT; // define function pointers and loadApiSymbols function// define possible names of libenum libNames = [ "mysharedlib.so", "mysharedlib.so.0", "mysharedlib.so.0.1", ];
// pointer to libraryprivate LibHandler lib;
voidinitMySharedLib()
{
// mysharedlib is already inited;if (lib !isnull) return;
// try load every possible library nameforeach (name; libNames)
{
lib = loadLibrary(name); // ssll callif (lib !isnull) break;
}
if (lib isnull) assert(0, "failed to load mysharedlib");
// ssll call: load symbols from shared library to functions pointers// assert if can't load symbol
loadApiSymbols(LoadApiSymbolsVerbose.assertion);
mysharedlib_init(); // some init function from mysharedlib
}
voidcleanupMySharedLib()
{
mysharedlib_cleanup(); // some cleanup from mysharedlib
unloadLibrary(lib); // ssll call: close lib and set pointer null
}
/+ place to define or import types+//+ define all needed functions "lib" is name of library pointer Linkage.c is linkage of pointer for loading functions addresses+/
@api("lib", Linkage.c)
{
// name of functions must match exactly with function in libraryvoidmysharedlib_init() { mixin(SSLL_CALL); }
voidmysharedlib_cleanup() { mixin(SSLL_CALL); }
// you must specify names of function parameters because they used in SSLL_CALLfloatmysharedlib_somefunc(int a, float b) { mixin(SSLL_CALL); }
...
}See example