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