本文介绍了什么是用C一个高效的工作流程? - Makefile的+ bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的第一个项目,将跨越多个C文件。对于我的第一对夫妇的实践方案,我只是写我的code在的main.c 并使用编译的gcc -o main.c中主要。这为我工作,因为我是学习。

I'm working on one of my first projects that will span more than one C file. For my first couple practice programs, I just wrote my code in main.c and compiled using gcc main.c -o main. This worked for me as I was learning.

现在,我的工作对我自己的一个更大的项目。我想继续我自己做的编译(或至少是手动设置它),所以我能理解的过程。读取位后,我决定做一个Makefile文件。

Now, I'm working on a much bigger project on my own. I want to continue doing compilation on my own (or at least setting it up manually) so I can understand the process. After reading a bit, I decided to make a Makefile.

请注意:我还使用GTK +,所以我不得不寻找如何添加到编译命令

Note: I'm also using GTK+, so I had to look up how to add that into the compile command.

这是什么样子了一些研究之后:

This is what it looks like after a bit of research:

main:
    gcc -Wall -g main.c -o main `pkg-config --cflags --libs gtk+-2.0`

起初,我只是跑制造。然后,我有得到错误的一些问题主要是最新的即使我已经改变了该文件。

At first, I was just running "make". Then I was having some problems getting the error "main is up to date" even though I had changed the file.

于是,我写了一个脚本:

So I wrote a script:

#!/bin/bash
rm main
make
./main

于是我做出改变,然后我运行此脚本。

So I make changes, and then I run this script.

这是一个很好的/正常的系统?我想有可扩展的系统,因为我的项目将会增加。我以为我能保持这种脚本,并只需添加依赖于Makefile和生成文件更改主编译命令。我是不是正确的?

Is this a good/normal system? I want to have scalable system, since my project will grow. I assume I can keep that script and just add dependencies to the makefile and change the main compile command in the makefile. Am I correct?

先谢谢了。

编辑:

感谢有关如何解决我的Makefile反馈。

Thanks for the feedback about how to fix my Makefile.

所以是典型的编译过程1)输入制作然后2) ./主不论怎么项目在设置或它的大小(假设你已经写了一个合适的makefile文件)?

So is the typical compilation process 1) type make then 2) ./main regardless of how the project is setup or its size (assuming you've written a proper makefile)?

推荐答案

您需要告诉做出取决于的main.c 。这样,每次修改的main.c 然后运行制作再生。要删除你可以叫假目标​​清洁为:

You need to tell make that main depends on main.c. That way every time you make changes to main.c and then run make, main is regenerated. To delete main you can have a phony target called clean as:

main:main.c
    gcc -Wall -g main.c -o main `pkg-config --cflags --libs gtk+-2.0`

.PHONY: clean
clean:
    rm -f main

现在删除你可以这样做:使清洁

Now to delete main you can do : make clean

如果你得到制作:主要是最新的这意味着你还没有修改的main.c 因此有是不需要再生。但如果你有强制再生即使在依赖尚未更新,你也可以使用 -B 选项的制作通过建议Sjoerd在其他的答案。

If you get make: main is up to date. It means you've not modified main.c and hence there is not need for regenerating main. But if you have to force regenerating main even when the dependencies have not been updated you can also use the -B option of make as suggested by Sjoerd in other answer.

这篇关于什么是用C一个高效的工作流程? - Makefile的+ bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:12