makefile格式-实践一
一直知道makefile是為了讓工程更合理化編譯和輸出~
從未在unix下自己寫這個;在windows開發中一直用ide開發,ide自帶;偶而寫寫小東西,也是用bat方式直接編譯。
ps:bat方式就是自己寫編譯命令;與makefile的區別是前者無論文件是否發生改變都編譯,后者是當編譯成功后若文件未發生任何改動,不會編譯;較之于前者,后者編譯效率高的多。
以前簡單學習了makefile,沒有動手實踐過;今天有興致簡單實踐一把。
實際環境:
net cs代碼
nmake
編寫簡單代碼: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 ?
第一次編寫makefile,如下:
1 all:helloworld.exe2
3 helloworld.exe:helloworld.cs
4 csc helloworld.cs
5
6 clean:
7 -del *.exe
直接用命令:nmake helloworld.makefile
報錯:fatal error U1034
想了半天,嘗試性的做了如下調整:
1 all:helloworld.exe2
3 helloworld.exe:helloworld.cs
4 csc helloworld.cs
5
6 clean:
7 -del *.exe
再使用命令,完全編譯通過
仔細看看兩個makefile,發現第四行和第七行有一個空格的差異。
閱讀《How to Write makefile.pdf》其中沒有此空格的注明,僅有如下規則:
target...:prerequisites...
command
【總結】:
實際的格式:
target...:prerequisites...
?command
此處空格意義:告知nmake"command"是目標的一個命令,而非下一個目標的開始。
另外不知道其他情況下,比如unix下是否有這個問題,也許僅僅只有nmake才有這個錯誤。有待后續測試結論
【2010-12-28】
繼續閱讀《How to Write makefile.pdf》,文中有這么一句:
最后,還值得一提的是,在Makefile中的命令,必須要以[Tab]鍵開始。
此話已說明命令在格式中的特殊起始點。上面所說" "空格不是標準的格式,可用而已
轉載于:https://www.cnblogs.com/GoGoagg/archive/2010/12/27/1917998.html
總結
以上是生活随笔為你收集整理的makefile格式-实践一的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#根据字节数截取字符串
- 下一篇: Win7启动Oracle出错