1. 生成so文件
2. 解析so文件
3. 调用so库函数
// // Created by gxf on 2020/2/27. // #include "hello.h" #include <stdio.h> #include <pthread.h> #include <unistd.h> #include <dlfcn.h> void *printMain(void *msg); void *logPrint(char *msg); int main() { void (*agentFunc)(char *msg); void *handle = dlopen("/Users/gxf/CLionProjects/untitled/hello/libhello.so", RTLD_LAZY); agentFunc = dlsym(handle, "say_hello"); agentFunc("hhhhhh"); return 0; } void *logPrint(char *msg) { printf("int main.c msg:%s\n", msg); } void* printMain(void *msg) { while(1) { printf("sleep in main :%s\n", (char *)msg); sleep(1); } }