C语言 生成文件扩展名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3962552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:43:51  来源:igfitidea点击:

makefile extension

cmakefile

提问by The Opposite of Garbage

I'm writing a C program using gcc in cygwin. My question is, how do you create a makefile? I mean, what file-extension does it have? I know how to write simple rules, but I can't save a file in the text-editor with the right extension? Impossible to find any info about this... This is prolly a super-newbie question. So let the flaming begin. :-P

我正在 cygwin 中使用 gcc 编写 C 程序。我的问题是,你如何创建一个makefile?我的意思是,它有什么文件扩展名?我知道如何编写简单的规则,但我无法在文本编辑器中使用正确的扩展名保存文件?无法找到有关此的任何信息......这是一个超级新手问题。所以让燃烧开始吧。:-P

回答by Peter G.

As you are using Cygwin which in turn means that you are using GNU make, I cite the relevant portion of the GNU make manual:

当您使用 Cygwin 时,这反过来意味着您使用的是 GNU make,我引用了 GNU make 手册相关部分

3.2 What Name to Give Your Makefile

By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile. Normally you should call your makefile either makefile or Makefile. (We recommend Makefile because it appears prominently near the beginning of a directory listing, right near other important files such as README.) The first name checked, GNUmakefile, is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU make, and will not be understood by other versions of make. Other make programs look for makefile and Makefile, but not GNUmakefile.

3.2 给你的 Makefile 起什么名字

默认情况下,当 make 查找 makefile 时,它​​会依次尝试以下名称:GNUmakefile、makefile 和 Makefile。通常,您应该将您的 makefile 称为 makefile 或 Makefile。(我们推荐 Makefile,因为它出现在目录列表开头的显眼位置,紧邻其他重要文件,例如 README。)大多数 makefile 不推荐使用第一个名称 GNUmakefile。如果您有一个特定于 GNU make 的 makefile,并且不会被其他版本的 make 理解,那么您应该使用这个名称。其他 make 程序查找 makefile 和 Makefile,但不查找 GNUmakefile。

[...]

[...]

If you want to use a nonstandard name for your makefile, you can specify the makefile name with the ‘-f' or ‘--file' option. The arguments ‘-f name' or ‘--file=name' tell make to read the file name as the makefile. If you use more than one ‘-f' or ‘--file' option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names GNUmakefile, makefile and Makefile are not checked automatically if you specify ‘-f' or ‘--file'.

如果要为 makefile 使用非标准名称,可以使用 '-f' 或 '--file' 选项指定 makefile 名称。参数 '-f name' 或 '--file=name' 告诉 make 读取文件名作为 makefile。如果您使用多个 '-f' 或 '--file' 选项,您可以指定多个 makefile。所有的 makefile 都按照指定的顺序有效地连接起来。如果指定'-f' 或'--file',则不会自动检查默认的makefile 名称GNUmakefile、makefile 和Makefile。

回答by Ignacio Vazquez-Abrams

The default filename for a makefile is Makefile; this is the name that GNU Make looks for when you run it without any options. The -fargument lets you specify an alternate filename if desired.

makefile 的默认文件名是Makefile; 这是 GNU Make 在没有任何选项的情况下运行时寻找的名称。-f如果需要,该参数允许您指定备用文件名。

回答by dmckee --- ex-moderator kitten

In the few places where I've seen extensions used on makefile names they have generally been either .makeor .gmk, and even then those extensions are usually reserved for makefile fragmentsthat are included by master files given one of the default names.

在少数几个我看到在 makefile 名称上使用扩展名的地方,它们通常是.make.gmk,即使这样,这些扩展名通常也保留给主文件包含的makefile片段,这些片段包含在给定默认名称之一的主文件中。

回答by slezica

They are usually named Makefile, or makefile. No extension. That's just convention, though.

它们通常被命名为Makefile, 或makefile。没有扩展。不过,这只是约定俗成。

It's not trivial to write a makefile, look up a guide or tutorial =)

编写 makefile、查找指南或教程并非易事 =)

回答by pmg

You can name them whatever you like, but ".mak" looks right.

您可以随意命名它们,但“.mak”看起来不错。

... google ... http://msdn.microsoft.com/en-us/library/aa380049%28VS.85%29.aspx... yeah

... 谷歌 ... http://msdn.microsoft.com/en-us/library/aa380049%28VS.85%29.aspx...是的

回答by Klaus Byskov Pedersen

A makefile is usually just called Makefile.

生成文件通常被称为Makefile.

回答by swestrup

Makefiles don't usually have an extension. They're typically called 'makefile' or 'Makefile'. Sometimes, when someone writes a complex set of makefiles that include each other, the included files get a .mak extension to indicate that they're makefiles even though they aren't called 'makefile'.

Makefile 通常没有扩展名。它们通常被称为“makefile”或“Makefile”。有时,当有人编写一组复杂的相互包含的 makefile 时,包含的文件会获得一个 .mak 扩展名,以表明它们是 makefile,即使它们不被称为“makefile”。

回答by Pablo Santa Cruz

Open your favorite text editor, and create a file named Makefile.

打开您最喜欢的文本编辑器,并创建一个名为Makefile.

Content might vary, but, provided you have a program called hello.ca very, very simple Makefileto compile it could be:

内容可能会有所不同,但是,如果您有一个名为hello.ca的程序,Makefile编译起来非常非常简单,它可能是:

hello: hello.c
     gcc -Wall hello.c -o hello.exe

After that you run run from cygwinshell:

之后,您从cygwinshell运行运行:

$ ls
hello.c Makefile
$ make
....

And your Makefilewill try to compile hello.c. If everything goes as expected, you can run the hello.exeprogram by executing the following shell command:

Makefile将尝试编译hello.c. 如果一切按预期进行,您可以hello.exe通过执行以下 shell 命令来运行程序:

$ ./hello.exe

Here's a nice tutorial on Makefiles.

这是关于Makefiles的一个很好的教程。