<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[一个简单的makefile示例及其注释]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 27 May 2010 02:54:33 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	　　相信在unix下编程的没有不知道makefile的，刚开始学习unix平台<br/>下的东西，了解了下makefile的制作，觉得有点东西可以记录下。<br/>　　下面是一个极其简单的例子：<br/>现在我要编译一个Hello world，需要如下三个文件：<br/>　　1. print.h<br/>　　　　　　#include&lt;stdio.h&gt;<br/>　　　　　　void printhello();<br/><br/>　　2. print.c<br/>　　　　　　#include&quot;print.h&quot;<br/>　　　　　　void printhello()&#123;<br/>　　　　　　　　printf(&quot;Hello, world&#92;n&quot;);<br/>　　　　　　&#125;<br/><br/>　　　3. main.c<br/>　　　　　　#include &quot;print.h&quot;<br/>　　　　　　int main(void)&#123;<br/>　　　　　　　　printhello();<br/>　　　　　　　　return 0;<br/>　　　　　　&#125;<br/><br/>　　好了，很简单的程序了。如果我们想要编译成功需要哪些步骤呢？<br/>我认为在这里需要理解的就两步：<br/>　　#&nbsp;&nbsp;为每一个 *.c文件生成 *o文件。<br/>　　#&nbsp;&nbsp;连接每一个*o文件，生成可执行文件。<br/>下面的makefile 就是根据这样的原则来写的。<br/><br/> <br/><br/>一：makefile 雏形：<br/><br/> <br/>#makefile的撰写是基于规则的，当然这个规则也是很简单的，就是：<br/>#target : prerequisites<br/>　　command　　//任意的shell 命令<br/><br/>实例如下：<br/>makefile:<br/>　　　　helloworld : main.o print.o #helloword 就是我们要生成的目标<br/>　　　　　　　　　　　　　　　　　# main.o print.o是生成此目标的先决条件<br/>　　　　　　gcc -o helloworld main.o print.o#shell命令，最前面的一定是一个tab键<br/><br/>　　　　mian.o : mian.c print.h<br/>　　　　　　gcc -c main.c<br/>　　　　print.o : print.c print.h<br/>　　　　　　gcc -c print.c<br/>　　　　<br/>　　　　clean :　　　　　　　　　　<br/>　　　　　　　　rm helloworld main.o print.o<br/>　　OK，一个简单的makefile制作完毕，现成我们输入 make，自动调用Gcc编译了，<br/>输入 make clean就会删除 hellowworld mian.o print.o<br/><br/><br/>二：小步改进：<br/><br/><br/>　　在上面的例子中我们可以发现 main.o print.o 被定义了多处，<br/>我们是不是可以向C语言中定义一个宏一样定义它呢？当然可以：<br/>makefile:<br/>　　　 objects =&nbsp;&nbsp;main.o print.o #应该叫变量的声明更合适<br/><br/>　　　　helloworld : $(objects) //声明了变量以后使用就要$()了<br/>　　　　　　gcc -o helloworld$(objects)<br/>　　　&nbsp;&nbsp;mian.o : mian.c print.h<br/>　　　　　　gcc -c main.c<br/>　　　　print.o : print.c print.h<br/>　　　　　　gcc -c print.c<br/>　　　　<br/>　　　　clean :　　　　　　　　　　<br/>　　　　　　　　rm helloworld $(objects)<br/>修改完毕，这样使用了变量的话在很多文件的工程中就能体现出方便性了。<br/><br/><br/>三：再进一步：<br/><br/><br/>　　再看一下，为没一个*.o文件都写一句gcc -c main.c是不是显得多余了，<br/>能不能把它干掉？而且 main.c 和print.c都需要print.h，为每一个都写上是<br/>不是多余了，能不能再改进？<br/>能，当然能了：<br/>makefile:<br/>　　　&nbsp;&nbsp;objects =&nbsp;&nbsp;main.o print.o<br/><br/>　　　　helloworld : $(objects)<br/>　　　　　　gcc -o helloworld$(objects)<br/>　　　　<br/>　　　　$(objects) : print.h # 都依赖print.h<br/>　　　&nbsp;&nbsp;mian.o : mian.c&nbsp;&nbsp;#干掉了gcc -c main.c 让Gun make自动推导了。<br/>　　　　print.o : print.c 　　　　<br/>　　　　clean :　　　　　　　　　　<br/>　　　　　　　　rm helloworld $(objects)<br/><br/>好了，一个简单的makefile就这样完毕了，简单吧。
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 一个简单的makefile示例及其注释]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>