免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 878 | 回复: 0
打印 上一主题 下一主题

Makefile DIY [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-04 23:18 |只看该作者 |倒序浏览
Makefile DIY
自己写的头文件一定要用“”来include不能用
“  ”中是不能随便在首尾加空格的,不然会找不到
include的意思是到/usr/include/目录下找xxx.h文件
include”xxx.h”是在当前目录下找xxx.h
今天执行make 又报错:missing separator.我到makefile里一看,命令前留出的空间都是空格而不是Tab,拷贝粘贴的东西就是没准啊
peter: peter.c
gcc peter.c –o peter
  above is a makefile I wrote today. I found that if the fist line was changed to “p:”, the whole makefile still worked perfectly. However, only “:” or nothing brought error.
”cc –c” turns .c file into .o file rather than executable file.
If I issual $make pos.o, then I get pos.o but no peter.
If the line “pos.o:$(obj)” is changed to “p:”, the makefile still works. Now I know lines like “target: dep” can be change at will. The computer does not care about it. However lines with Tab at the beginning are shell commands which shall be written carefully.
I am lucky to know I was wrong. Those”target:dep” lines sometimes do matter.
  @@@peter:peter.o
   cc –o peter peter.c
                     
then I issue $make, a peter.o file shows up. But if the file line of the above makefile is changed into “peter:”, then make, only a exe file peter will show up. The reason is simple, if the firstline is “peter:peter.o”, the compile system believe you intend to issue a commmand $cc –o peter.o –c peter.c. However, if “peter:”, I think the system will take it as a phony targets, even though I am not sure but the idea does make sense.
Now I take a next step to know more about it. When the first line is “peter:”, the makefile works peterfectly, nevertheless when peter.c is change and you issue $make again, the exe file won’t be updated, which merans the makefile is a broken one.
So I change it into “peter:peter.c”, problem is solved.

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56913/showart_489544.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP