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

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM