linux下c程式開發過程簡單一實例

來源:互聯網
上載者:User

標籤:io   ar   sp   檔案   bs   ad   ef   linux   程式   

編輯

******max.h*********

int max(int, int);

*****max.c*********

#include "max.h"

int max(int a, int b)

{

  return (a > b) ? a : b;

}

******min.h*******

int min(int, int);

******min.c*******

#include "min.h"

int min(int a, int b)

{

  return (a<b) ? a : b;

}

*******main.c**********

#include <stdio.h>

#include "max.h"

#include "min.h"

int main(int argc, char** argv)

{

  int a = 10, b = 20;

  printf("最大值:%d", max(a, b));

  printf("最小值:%d", min(a, b));

  return 0;

}

編譯

產生可執行檔:gcc main.c max.c min.c -o test

產生靜態庫:

gcc -c max.c min.c

ar cr libtest.a max.o min.o

gcc -o test main.c -L. -ltest

產生共用庫:

gcc -c -fPIC max.c min.c

gcc -shared -fPIC -o libtest.so max.o min.o

註:-lm串連數學庫、-lpthread連接線程庫、-g可調試

makefile

main: main.o max.o min.o

  gcc -o main main.o max.o min.o

main.o: main.c max.h min.h

  gcc -c main.c

max.o: max.c max.h

  gcc -c max.c

min.o: min.c min.h

  gcc -c min.c

clean:

  rm *.o

簡化後:

main: main.o max.o min.o

  gcc -o [email protected] $^

.c.o:

  gcc -c $<

 

linux下c程式開發過程簡單一實例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.