S(ymbol) H(elper) is a basic STB-Style for the WIN32 LoadLibrary and POSIX dlopen functions to maintain a basic yet consistent API for both platforms.
Linux/MacOS Steps:
cc -Wall -Wextra -ldl -Isrc/ example/main.c -o application
cc -shared -fPIC -Wall -Wextra -Isrc example/lib.c -o lib.so
./application
Windows Steps: *
cl /Feapplication.exe /I"src" example/main.c
cl /Felib.dll /LD /I"src" example/lib.c
.\application.exe
Note: All Windows testing was performed using PortableBuildTools and not tested using Visual Studio
// main.c
#define SH_IMPLEMENTATION
#include <sh.h>
int main () {
SH_LibHandle lib = SH_LoadLibraryEx (SH_LOCAL_DIR, SH_LIBNAME ("lib"));
SH_VoidFunction test_function = SH_GetSymbol (lib, "LIB_TestFunction");
if (test_function != NULL) {
test_function ();
}
SH_CloseLibrary (lib);
return 0;
}
// lib.c
#include <sh.h>
#include <stdio.h>
SH_EXPORT void LIB_TestFunction () {
printf ("Hello from LIB_TestFunction!\n");
}