您的位置:首页 > 其它

make -n(仅列出命令, 但不会执行)用于调试makefile

2016-11-05 22:39 357 查看
        我们先来看一个简单程序:

#include <iostream>
using namespace std;

int main()
{
cout << "hello world" << endl;

return 0;
}
       然后来看看makefile:

main: main.o
g++ -o main main.o
main.o: main.cpp
g++ -o main.o -c main.cpp

clean:
rm -f main *.o
      看一下执行结果:

taoge@localhost Desktop> make
g++ -o main.o -c main.cpp
g++ -o main main.o
taoge@localhost Desktop> ls
main main.cpp main.o makefile
taoge@localhost Desktop> make clean
rm -f main *.o
taoge@localhost Desktop> ls
main.cpp makefile
<pre name="code" class="plain">taoge@localhost Desktop>
taoge@localhost Desktop>
taoge@localhost Desktop>
taoge@localhost Desktop> make -ng++ -o main.o -c main.cppg++ -o main main.otaoge@localhost Desktop> lsmain.cpp makefile


       可以看到, 执行make -n的时候, 并没有生成真正的文件, 因为这知识一个调试命令, 它仅仅列出即将执行的命令, 但不会具体执行命令。 很多时候, 我们调试makefile的时候, 需要用到-n参数。

       再来看一下:

taoge@localhost Desktop>:~/test> make
g++ -o main.o -c main.cpp
g++ -o main main.o
taoge@localhost Desktop>:~/test> make -n
make: `main' is up to date.
       一目了然。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: