Linux GCC G 生成動態庫或者靜態庫

2021-09-07 03:03:29 字數 642 閱讀 6991

生成靜態庫之前要使用

gcc -c 編譯生成 *.o 檔案

然後使用

ar -rcs *.a *.o

生成靜態庫

動態庫有別名真名鏈結名

命令:

gcc -shared -fpic -wl,-soname,libname.so -o libname.so.0 *.c

-shared 動態鏈結庫

-fpic 生成的鏈結庫與路徑無關

-wl 選項告訴編譯器將後面的引數傳遞給鏈結器。

-soname 動態庫的別名

-o 動態庫的真名

該動態庫的連線名字就是name

使用ldconfig 新增動態鏈結庫到快取中

命令:lfconfig 【目錄】

使用時

gcc -o 【可執行檔名】 -l【鏈結庫路徑】 -l【鏈結庫鏈結名】

Linux gcc g 靜態庫與動態庫

原始碼 test.h pragma once void test test.c include stdio.h void test hello.h pragma once void hello const char name hello.c include stdio.h include hello...

cmake 生成 動態庫

一,目錄結構 cmakelists.txt include shared hello.h src hello.cpp main.cpp link cmakelists.txt contains the cmake commands you wish to run link include share...

編譯生成動態庫 鏈結動態庫生成可執行檔案

折騰了一天編譯 動態庫的問題,整理一下 參考 現有4個檔案 head.h 庫標頭檔案 source1.cc 庫原始檔1 source2.cc 庫原始檔2 include stdio.h include stdlib.h include head.h int main 庫標頭檔案head.h裡是庫原始...