Logo Questions Linux Laravel Mysql Ubuntu Git Menu

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.

enter image description here

like image 492
kjs Avatar asked Mar 15 '23 09:03


1 Answers

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.


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
like image 77
Philip Couling Avatar answered Mar 16 '23 22:03

Philip Couling