bash 如何在ubuntu中运行makefile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33280898/
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-08 22:07:30  来源:igfitidea点击:

how to run makefile in ubuntu

bashubuntumakefile

提问by kjs

There are two simple .c files add.c and hello.c. this is my makefile-

有两个简单的 .c 文件 add.c 和 hello.c。这是我的makefile-

all:  add.exe hello.exe

add.exe: add.o

    gcc -o add.exe add.o



hello.exe: hello.o

    gcc -o hello.exe hello.o



add.o: add.c 

    gcc -c add.c



hello.o: hello.c 

    gcc -c hello.c

on typing makeon terminal it shows all those four commands, but when i try to run this using ./allit says

make终端上打字时,它显示了所有这四个命令,但是当我尝试使用./all它运行它时,它说

bash: ./all: No such file or directory. 

./hello.exeor ./add.exeworks fine.

./hello.exe./add.exe工作正常。

when I type ./all on my friend's pc, it shows proper output.

当我在我朋友的电脑上输入 ./all 时,它显示了正确的输出。

enter image description here

在此处输入图片说明

回答by Philip Couling

Your friend's PC is doing something strange and its not clear from your question what they've done. Your PC is acting normally.

您朋友的 PC 正在做一些奇怪的事情,从您的问题中不清楚他们做了什么。您的 PC 运行正常。

Calling make allWill compile everything, but it doesn't actually make a program called all. It only compiles two programs: hello.exeand add.exe.

调用make all将编译所有内容,但它实际上并没有创建一个名为all. 它只编译两个程序:hello.exeadd.exe.

So calling ./allshould fail because that is asking to run a program called allwhich doesn't exist.

所以调用./all应该失败,因为这要求运行一个all不存在的程序。

It's quite possible that your friend has written themselves a program or script called "all". You'll need to ask your friend what that script / program does and how it does it.

您的朋友很可能为自己编写了一个名为“all”的程序或脚本。您需要询问您的朋友该脚本/程序的作用以及它是如何工作的。

Edit

编辑

To see what your friend has done open a terminal on your friends pc (like the one in your screen shot) and type the command

要查看你的朋友做了什么,在你朋友的电脑上打开一个终端(就像你屏幕截图中的那个)并输入命令

ls -lh

This will list all the files in that directory. Look for one named "all". It might look something like this (with the word "all" in green):

这将列出该目录中的所有文件。寻找一个名为“all”的人。它可能看起来像这样(“全部”一词为绿色):

-rwxr-----  1 appy appy 67 Oct 23 15:05 all

Assuming that's there you can look at the contents of it by typing

假设在那里你可以通过键入来查看它的内容

cat ./all

To get yours to work like your friends, create a similar file with the same contents. To make it runnable you may need to change the file permissions:

要让您的文件像您的朋友一样工作,请创建一个内容相同的类似文件。要使其可运行,您可能需要更改文件权限:

chmod u+x all

回答by twalberg

"all" in this case is what is called a "pseudo-target" in maketerminology. Since there is no build command under the all: ...line, there is nothing that will actually create a file called all(and in fact, having a file in that directory named alland having a timestamp newer than the .c, .oand .exefiles is likely to confuse make). The pseudo-target here is simply a way to say that both the other .exefiles must be built for maketo consider its job done.

在这种情况下,“全部”是make术语中所谓的“伪目标” 。由于该all: ...行下没有构建命令,因此实际上不会创建一个名为的文件all(事实上​​,在该目录中all有一个名为的文件,并且时间戳比和文件新.c,文件可能会混淆)。这里的伪目标只是表示必须构建其他两个文件才能考虑完成其工作的一种方式。.o.exemake.exemake

Assuming this is GNU Make, an entry .PHONY: allwill tell it that alldoes not really correspond to a file that should exist.

假设这是 GNU Make,一个条目.PHONY: all将告诉它all并不真正对应于应该存在的文件。