linux---動靜態庫編譯及使用

靜態庫

xxx.a

動態庫

xxx.so



例子

ku.c


#include <stdio.h>


int helloku(void)

{    

    printf("hello ku\r\n");

    return 0;

}


ku.h


#ifndef __KU__

#define __KU__

int helloku(void);


#endif


gcc -c ku.c生成ku.o



編譯生成靜態庫

ar crv libku.a  ku.o


test.c

#inckude "ku.h"

int main(void)

{

    helloku();

    return 0;

}

gcc test.c -o test -L./  -lku




編譯生成動態庫

gcc -shared -fPCI -o libku.so  ku.o


gcc test.c -o test -L./ -lku

注意:要將libku.so放到 /usr/lib下面


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章