c 解析so文件

1. 生成so文件 https://www.cnblogs.com/luckygxf/p/11894773.html

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

  

posted on 2020-03-01 11:55  luckygxf  阅读(812)  评论(0编辑  收藏  举报

导航