This function is ridiculous, but I wrote it anyway.
The docs pretty much explain how it works, but here's an example of it in use:
#include "dlib_import.c"
// function declarations for zlib / dynamic library
unsigned long (*compressBound)(unsigned long length);
int (*compress)(void *dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
int (*decompress)(void *dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
// main function, simply loads library & exits
int main() {
return dlib_import("libz.so", 3,
(char*) &compressBound, "compressBound",
(char*) &compress, "compress",
(char*) &decompress, "uncompress"
);
}
Same as usual. Don't forget the -ldl
flag!
gcc main.c -ldl -g -o main