Morpheus
Morpheus

Reputation: 3523

C++ compiler output is not running due to permisson error

I have the following make file:

CC=g++

CFLAGS=-c -Wall

1: 
    $(CC) $(CFLAGS) 03_datatypes.cpp -o program
    ./program

and as you can see I am trying to run the program file after compiling. I am getting the following error:

 make: execvp: ./program: Permission denied
 makefile:7: recipe for target '1' failed
 make: *** [1] Error 127

I was using makefiles like this before on a different computer but never faced this issue before.

As suggested by someone below: I tried to chmod +x program but I am getting a different error

 bash: ./program: cannot execute binary file: Exec format error 

Upvotes: 0

Views: 524

Answers (2)

user2100815
user2100815

Reputation:

Your CFLAGS:

   CFLAGS=-c -Wall

tell the compiler to produce a .o file (which you then rename with the -o option), but not to link it. And .o files are not executable. Remove the -c option.

Upvotes: 2

Surojit
Surojit

Reputation: 1292

Looks like you are on a linux system and do not have execute permission set on the program binary.

Before you try to run the program, give it execute permissions by chmod +x program.

Upvotes: 0

Related Questions