准备三个文件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

gcc生成so文件

 备注:这里编译main.c需要提供.h头文件,不然会报编译错误

相关文章:

  • 2021-12-05
  • 2021-10-31
  • 2021-06-27
  • 2022-02-18
猜你喜欢
  • 2021-10-31
  • 2022-12-23
  • 2021-10-20
  • 2021-12-05
  • 2022-01-14
  • 2021-12-25
  • 2021-09-16
相关资源
相似解决方案