Load mod dynamically
This commit is contained in:
parent
472dff7d80
commit
86a8a6c5f7
2
build.sh
2
build.sh
@ -2,4 +2,4 @@
|
|||||||
CFLAGS="-std=c11 -pedantic -Wall -Wextra"
|
CFLAGS="-std=c11 -pedantic -Wall -Wextra"
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
clang $CFLAGS -fPIC -shared mod.c -o build/libmod.so
|
clang $CFLAGS -fPIC -shared mod.c -o build/libmod.so
|
||||||
clang $CFLAGS -Lbuild -lmod main.c -o build/demo
|
clang $CFLAGS main.c -o build/demo
|
||||||
|
7
main.c
7
main.c
@ -5,13 +5,16 @@
|
|||||||
|
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
|
|
||||||
#include "mod.h"
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
typedef const char *(*getmsg_t)(void);
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
void *mod = dlopen("libmod.so", RTLD_NOW);
|
||||||
|
const getmsg_t getmsg = (getmsg_t)dlsym(mod, "getmsg");
|
||||||
const struct timespec pause = { .tv_nsec = 16666667 };
|
const struct timespec pause = { .tv_nsec = 16666667 };
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("\33[2K\r%s", getmsg());
|
printf("\33[2K\r%s", getmsg());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user