溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux makefile問題怎么解決

發(fā)布時(shí)間:2021-12-24 14:03:34 來源:億速云 閱讀:150 作者:iii 欄目:系統(tǒng)運(yùn)維

這篇文章主要講解了“Linux makefile問題怎么解決”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linux makefile問題怎么解決”吧!

將各個(gè)模塊的關(guān)系寫進(jìn)makefile,并且寫明了編譯命令,這樣,當(dāng)有模塊的源代碼進(jìn)行修改后,就可以通過使用make命令運(yùn)行makefile文件就可以進(jìn)行涉及模塊修改的所有模塊的重新編譯,其他模塊就不用管了。

makefile文件的寫法:

目標(biāo), 組件
規(guī)則

例如 有下面5個(gè)文件:

/* main.c */
#include "mytool1.h"
#include "mytool2.h"
int main(int argc,char **argv)
{
mytool1_print("hello");
mytool2_print("hello");
}
/* mytool1.h */
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
void mytool1_print(char *print_str);
#endif
/* mytool1.c */
#include "mytool1.h"
void mytool1_print(char *print_str)
{
printf("This is mytool1 print %s\n",print_str);
}
/* mytool2.h */
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
void mytool2_print(char *print_str);
#endif
/* mytool2.c */
#include "mytool2.h"
void mytool2_print(char *print_str)
{
printf("This is mytool2 print %s\n",print_str);
}

可以這樣進(jìn)行編譯以便運(yùn)行main這個(gè)可執(zhí)行文件

gcc -c main.c (生成main.o)
gcc -c mytool1.c (生成mytool1.0)
gcc -c mytool2.c (生成mytool2.0)
gcc -o main main.o mytool1.o mytool2.o (生成main)

也可以這樣寫makefile文件

main main.o mytool.o mytool2.o
gcc -0 $@ $^
main.0 main.c mytool1.h mytool2.h
gcc -c $<
mytool1.0 mytool1.c mytool1.h
gcc -c $<(或者是mytool.c)
mytool2.0 mytool2.c mytool2.h
gcc -c $<(或者是mytool2.c)

通過make命令可以運(yùn)行該文件,也就是進(jìn)行編譯了。

Linux上有很多庫,c語言編寫的各種庫的總稱為libc,glibc為libc的一個(gè)子集,由gnu提供,內(nèi)核提供的系統(tǒng)函數(shù)和系統(tǒng)調(diào)用是不包括在libc中。

Linux系統(tǒng)默認(rèn)會(huì)安裝glibc

glibc中

常用庫gcc會(huì)自動(dòng)去查找,不予理會(huì)。

在/lib, /usr/lib, /usr/local/lib 在這三個(gè)路徑下面有一些標(biāo)準(zhǔn)庫,只需-l+庫名 可以不必要指定路徑。其他庫必須在用gcc時(shí)用-L+具體的路徑。通過本文你就能全面了解Linux makefile。

感謝各位的閱讀,以上就是“Linux makefile問題怎么解決”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Linux makefile問題怎么解決這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI