简体   繁体   中英

how to run makefile in ubuntu

There are two simple .c files add.c and hello.c. this is my 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 make on terminal it shows all those four commands, but when i try to run this using ./all it says

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

./hello.exe or ./add.exe works fine.

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

在此输入图像描述

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

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

So calling ./all should fail because that is asking to run a program called all which doesn't exist.

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.

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):

-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

"all" in this case is what is called a "pseudo-target" in make terminology. 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 all and having a timestamp newer than the .c , .o and .exe files is likely to confuse make ). The pseudo-target here is simply a way to say that both the other .exe files must be built for make to consider its job done.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM