iOS 加载动态库

来源:互联网 发布:木子软件 官网app 编辑:程序博客网 时间:2024/04/30 13:07

1)iOS加载动态库

#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <dlfcn.h> /* 必须加这个头文件 */#include <assert.h>int main(int argc, char *argv[]){    printf("come in\n");    void *handler = dlopen("libtest.so", RTLD_NOW);    assert(handler != NULL);        void (*pTest)(int);    pTest = (void (*)(int))dlsym(handler, "add");        (*pTest)(10);    dlclose(handler);        printf("go out\n");    return 0;}


2)静态库

#include <stdio.h>#ifdef __cplusplusextern "C"{    #endif    void add(int num){    printf("*****************************************\n");    printf("This is ok, the number is okay. %d\n", num);    printf("*****************************************\n");}#ifdef __cplusplus    }    #endif