linux 編譯時間多個源檔案產生一個目標檔案,linux源檔案

來源:互聯網
上載者:User

linux 編譯時間多個源檔案產生一個目標檔案,linux源檔案

obj-m := target.o  

target-objs :=  src1.o src2.o src3.o 


怎在linux shell中同時編譯一個源檔案與一個標頭檔,使其產生一個可執行檔

直接用gcc編譯.c檔案,.c檔案中 #include "標頭檔" 即可。
gcc test.c -o output -Wall
其中,output為輸出的可執行檔,-Wall開關用於顯示所有警告資訊。
 
linux下 c語言多檔案編譯

如果有多個源檔案,基本上有兩種編譯方法:
[假設有兩個源檔案為test.c和testfun.c]

1. 多個檔案一起編譯
用法:#gcc testfun.c test.c -o test
作用:將testfun.c和test.c分別編譯後連結成test可執行檔。

2. 分別編譯各個源檔案,之後對編譯後輸出的目標檔案連結。
用法:
#gcc -c testfun.c //將testfun.c編譯成testfun.o
#gcc -c test.c //將test.c編譯成test.o
#gcc -o testfun.o test.o -o test //將testfun.o和test.o連結成test

以上兩種方法相比較,第一中方法編譯時間需要所有檔案重新編譯,而第二種方法可以只重新編譯修改的檔案,未修改的檔案不用重新編譯。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.