C 語言筆記
  • Introduction
  • GCC 編譯器
  • 使用Visual Studio
  • Header Files
    • stat.h
  • 型別
    • 指標
    • 字串
  • 建立 Library
  • Linux kernel
  • Stack pointer、Frame pointer
  • 相關推薦資料
Powered by GitBook
On this page
  • 1. Static libraries
  • 使用

Was this helpful?

建立 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();
}

輸入

gcc main.c libmylib.a /* 產生出 a.out */
./a.out /* 執行程式 */
Previous字串NextLinux kernel

Last updated 4 years ago

Was this helpful?

參考:

https://blog.xuite.net/csiewap/cc/23626229-Using+GCC+to+create+static+and+shared+library+.so