建立 Library
1. Static libraries
hello.c
#include <stdio.h>
void hello(){ printf("Hello "); }world.c
#include <stdio.h>
void world(){ printf("world."); }mylib.h
void hello();
void world();於 command line 輸入
gcc -c hello.c world.c /* 編出 hello.o 與 world.o */
ar rcs libmylib.a hello.o world.o /* 包成 limylib.a 必須是lib<>.a 命名 */ 使用
main.c
#include "mylib.h"
int main() {
hello();
world();
}輸入
參考:https://blog.xuite.net/csiewap/cc/23626229-Using+GCC+to+create+static+and+shared+library+.so
Last updated
Was this helpful?