简单的make文件问题(C)

发布于 2024-09-29 05:20:36 字数 485 浏览 2 评论 0原文

嘿,我是 C 语言新手,但总的来说是中级程序员。我正在寻找制作文件的方法,但在弄清楚它们的用途以及如何使用它们时遇到了问题。例如,我当前正在通过键入以下内容单独编译项目中的每个文件:

gcc -o newoutfilename1.out oldcfilename1.c
gcc -o newoutfilename2.out oldcfilename2.c

现在,如果我只想运行一个 make 文件来一次编译所有文件,该怎么办?我不想最后将它们全部放入一个文件中,看看它们如何没有链接。也走得更前。可以使用 makefile 进行测试吗?就像我编译到 newoutfilename1.out 后一样,我想运行:

./newoutfilename1.out arg1 arg2 arg3 > intothisfile.data

通常在编码和测试代码是否编译并输出正确的数据时使我的生活更轻松。

Hey so I a new to C but a intermediate level programmer in general. I'm looking in to make files and having issues figuring out exactly what they are for, and how to use them. So for example I am currently compiling each of my files in my project individually by typing:

gcc -o newoutfilename1.out oldcfilename1.c
gcc -o newoutfilename2.out oldcfilename2.c

Now what if I just wanted to run a make file to compile them all at once. I don't want to put them all into one file at the end seeing how they are not linked. Also going more advance. Can a makefile be used for testing. Like after I compile to newoutfilename1.out I want to run:

./newoutfilename1.out arg1 arg2 arg3 > intothisfile.data

Generally making my life easier while coding and testing if the code compiles and out puts the correct data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷子口的你 2024-10-06 05:20:36

Interwebs 上有一些 GNU Make 教程。谷歌出现了一些点击率。您可以从这个开始。

There are several GNU Make tutorials on the Interwebs. Google turned up a number of hits. You might start with this one.

岛歌少女 2024-10-06 05:20:36

好吧,

凯林,你提供的那个链接,你想读一下吗?

老实说,如果我没有在生活中编写过 100 个 make 文件,我将无法理解您链接的帖子中的一个单词。

makefile 是一种特殊的脚本。

每行看起来像这样:

target: depends-on.c and.h and-even-another.h  
  command -o target depends-on.c

第一行是所有文件,第二行是在“:”之前创建文件的命令,

所以是一个文件。如果目标早于“depends-on.c”或“and.h”或“and-even-another.h”,则执行第二行中的命令(假设它将创建/重新生成/输出文件“target” '),如果编译成源文件,这些文件通常称为 target.o。

换句话说:一行描述输出是什么,冒号后面是输出所依赖的文件,第二行是创建输出的命令。

“:”左边的东西称为“目标”。

目标可以依赖于其他目标。

您可以使用通配符。

*.o: *.c   
  cc -o "something you have to look up, dont now it from my mind ;D"

program: *.o  
  ln *.o my.lib another.lib 

上面仅编译那些比相应的 *.o 文件更新的 *.c 文件,然后将所有 *.o 文件与两个命名库链接在一起。

如果您使用的是 linux/unix 机器,请尝试“man make”。否则谷歌;D

安吉洛

Well,

that link you gave, Kaelin, did you care to read it?

Honestly if I had not written a few 100 make files in my live I would not understand a single word in that posting you linked.

A makefile is a kind of special script.

Every line looks like this:

target: depends-on.c and.h and-even-another.h  
  command -o target depends-on.c

First line are all files, second line is a command to create the file before the ":"

So is a file. If target is older than 'depends-on.c' or 'and.h' or 'and-even-another.h' then the command in the second line is executed (assuming it will create/regenerate/output the file 'target'), usually those files are called target.o, if compiled form a source file.

In other words: one line to describe what the output is, after the colon the files the output depends upon and in the second line the command to create the output.

The thing left of the ':' is called the 'target'.

Targets can depend on other targets.

You can use wildcards.

*.o: *.c   
  cc -o "something you have to look up, dont now it from my mind ;D"

program: *.o  
  ln *.o my.lib another.lib 

The above only compiles those *.c files that are newer than the corresponding *.o files and then links all *.o files together with the two named libraries.

If you are on a linux/unix machine try "man make". Otherwise google ;D

Angelo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文