Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 1.22 KB

README.md

File metadata and controls

55 lines (40 loc) · 1.22 KB

(SH)ell

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.

Building Examples

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

Example Code

// 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");
}