gcc生成so文件

准备三个文件test.h, test.c, main.c

test.h

#include <stdio.h>

void say_hello();

test.c

#include "test.h"

void say_hello(char *name){
    printf("hello %s\n", name);
}

main.c

#include "test.h"

int main(){
    say_hello("guanxianseng");

    return 0;
}

执行生成so文件命令

gcc test.c -fPIC -shared -o libtest.so

编译生成main可执行文件

gcc main.c  -L. -ltest -o main

猜你喜欢

转载自www.cnblogs.com/luckygxf/p/11894773.html