博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
makefile中“-“符号的使用
阅读量:4139 次
发布时间:2019-05-25

本文共 1422 字,大约阅读时间需要 4 分钟。

       在makefile中,  -用预告诉make命令忽略当前错误, 继续执行, 我们来简单看下:

 

main: main.o 	g++ -o main main.omain.o: main.cpp	g++ -o main.o -c main.cppclean:	rm main *.o

        执行结果为:

 

 

taoge@localhost Desktop> make cleanrm main *.otaoge@localhost Desktop> make cleanrm main *.orm: cannot remove `main': No such file or directoryrm: cannot remove `*.o': No such file or directorymake: *** [clean] Error 1

        此时, 可以把makefile中的 rm main *.o替换为: -rm main *.o  , 它会忽略这些错误。 当然, 在此处, 也可以用rm -f main *.o来处理。

 

        这个命令是非常有用的, 我们来看一个例子:

        makefile为:

 

main: main.o 	g++ -o main main.omain.o: main.cpp	g++ -o main.o -c main.cppclean:	rm main	rm 1.o	rm 2.o

 

 

taoge@localhost Desktop> lsmain.cpp  makefiletaoge@localhost Desktop> touch main 2.otaoge@localhost Desktop> ls2.o  main  main.cpp  makefiletaoge@localhost Desktop> make cleanrm mainrm 1.orm: cannot remove `1.o': No such file or directorymake: *** [clean] Error 1taoge@localhost Desktop> ls2.o  main.cpp  makefile

       可见, 前面的rm 1.o失败, 后面的不会执行, 改为:

 

 

main: main.o 	g++ -o main main.omain.o: main.cpp	g++ -o main.o -c main.cppclean:	-rm main	-rm 1.o	-rm 2.o
taoge@localhost Desktop> lsmain.cpp  makefiletaoge@localhost Desktop> touch main 2.otaoge@localhost Desktop> ls2.o  main  main.cpp  makefiletaoge@localhost Desktop> make cleanrm mainrm 1.orm: cannot remove `1.o': No such file or directorymake: [clean] Error 1 (ignored)rm 2.otaoge@localhost Desktop> lsmain.cpp  makefiletaoge@localhost Desktop>

        可见, 及时rm 1.o出错, 也会被ignored, 继续往下执行。

 

 

 

转载地址:http://sggvi.baihongyu.com/

你可能感兴趣的文章
Pentaho 开发: 在eclipse中构建Pentaho BI Server工程
查看>>
JSP的内置对象及方法
查看>>
android中SharedPreferences的简单例子
查看>>
android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
查看>>
andorid里关于wifi的分析
查看>>
Spring MVC和Struts2的比较
查看>>
Hibernate和IBatis对比
查看>>
Spring MVC 教程,快速入门,深入分析
查看>>
Android 的source (需安装 git repo)
查看>>
Commit our mod to our own repo server
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Simple Guide to use the gdb tool in Android environment
查看>>
Netconsole to capture the log
查看>>
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
apache和tomcat整合
查看>>