makefile格式-实践一
一直知道m(xù)akefile是為了讓工程更合理化編譯和輸出~
從未在unix下自己寫(xiě)這個(gè);在windows開(kāi)發(fā)中一直用ide開(kāi)發(fā),ide自帶;偶而寫(xiě)寫(xiě)小東西,也是用bat方式直接編譯。
ps:bat方式就是自己寫(xiě)編譯命令;與makefile的區(qū)別是前者無(wú)論文件是否發(fā)生改變都編譯,后者是當(dāng)編譯成功后若文件未發(fā)生任何改動(dòng),不會(huì)編譯;較之于前者,后者編譯效率高的多。
以前簡(jiǎn)單學(xué)習(xí)了makefile,沒(méi)有動(dòng)手實(shí)踐過(guò);今天有興致簡(jiǎn)單實(shí)踐一把。
實(shí)際環(huán)境:
net cs代碼
nmake
編寫(xiě)簡(jiǎn)單代碼:helloworld
1 using System;2 ?using System.Collections.Generic;
3 ?using System.Text;
4
5 ?namespace ConsoleApplication1
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 string s = "Hello";
12 s = s + " world";
13
14 Console.WriteLine(s);
15
16 Console.Read();
17 }
18 }
19 }
20 ?
第一次編寫(xiě)makefile,如下:
1 all:helloworld.exe2
3 helloworld.exe:helloworld.cs
4 csc helloworld.cs
5
6 clean:
7 -del *.exe
直接用命令:nmake helloworld.makefile
報(bào)錯(cuò):fatal error U1034
想了半天,嘗試性的做了如下調(diào)整:
1 all:helloworld.exe2
3 helloworld.exe:helloworld.cs
4 csc helloworld.cs
5
6 clean:
7 -del *.exe
再使用命令,完全編譯通過(guò)
仔細(xì)看看兩個(gè)makefile,發(fā)現(xiàn)第四行和第七行有一個(gè)空格的差異。
閱讀《How to Write makefile.pdf》其中沒(méi)有此空格的注明,僅有如下規(guī)則:
target...:prerequisites...
command
【總結(jié)】:
實(shí)際的格式:
target...:prerequisites...
?command
此處空格意義:告知nmake"command"是目標(biāo)的一個(gè)命令,而非下一個(gè)目標(biāo)的開(kāi)始。
另外不知道其他情況下,比如unix下是否有這個(gè)問(wèn)題,也許僅僅只有nmake才有這個(gè)錯(cuò)誤。有待后續(xù)測(cè)試結(jié)論
【2010-12-28】
繼續(xù)閱讀《How to Write makefile.pdf》,文中有這么一句:
最后,還值得一提的是,在Makefile中的命令,必須要以[Tab]鍵開(kāi)始。
此話已說(shuō)明命令在格式中的特殊起始點(diǎn)。上面所說(shuō)" "空格不是標(biāo)準(zhǔn)的格式,可用而已
轉(zhuǎn)載于:https://www.cnblogs.com/GoGoagg/archive/2010/12/27/1917998.html
總結(jié)
以上是生活随笔為你收集整理的makefile格式-实践一的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C#根据字节数截取字符串
- 下一篇: Win7启动Oracle出错