Skip to content

Instantly share code, notes, and snippets.

@patham9
Created October 28, 2023 07:26
Show Gist options
  • Save patham9/d8615121e1b5c1f18a7c66be34ab5b23 to your computer and use it in GitHub Desktop.
Save patham9/d8615121e1b5c1f18a7c66be34ab5b23 to your computer and use it in GitHub Desktop.
Simple dll usage (never use dlopen if your program just needs to load the library at startup!!)
/* add.c */
#include <stdio.h>
float add(float a, float b) { return a + b; }
//gcc -shared -o libadd.so add.c -fPIC
/* main.c */
#include <stdio.h>
extern float add(float a, float b);
int main() { printf("Result: %f\n", add(3.0, 4.0)); return 0; }
//gcc main.c -L. -ladd
//./a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment