Reputation: 342
I'm trying to make a C++ program that will find the shortest route out of the a maze. I'm struggling to get my makefile to work right now though. Currently, my makefile contains the following:
mazeIO : mazeIO.cpp maze.h
g++ -g -Wall mazeIO.cpp maze.h -o mazeIO
mazeIO.cpp and maze.h are the only two files I have in the project. In the command line I am typing
make -f Makefile
and it compiles fine. Then I am typing
./mazeIO maze.txt
maze.txt is the maze input that I am trying to navigate. After I type this in I get the following error:
bash: ./mazeIO: Permission denied
I do not understand why. Any suggestions?
Upvotes: 6
Views: 49310
Reputation: 205
This is simple. It needs executable rights.
chmod +x mazeIO
You can also use chmod if it needs to be executed by other users.
man chmod
will give you the numeric values needed if it needs to be executed by other users. Be wary of giving full executable, read, and write rights (chmod 777
)
chmod 600
will not make it executable.
Upvotes: 6
Reputation: 77
This does not fix the original question as stated, but I will share a possible solution for anyone seeing this same behavior (getting bash: ./mazeIO: Permission denied
).
I was getting this error in a project because my Makefile was using the -c
flag. This flag lets g++ compile and assemble project files but doesn’t link them, so the compiler creates a file that will appear to be the executable you are expecting but it is not actually an executable. The solution is to remove this flag.
Upvotes: 1
Reputation: 198314
Executable files are known as executable in Linux due to the presence of the execute (x
) flag. Your "executable" doesn't have it - it only has the read (r
) and write (w
) permissions. Either you strip the permission from the executable (say, using chmod 600 mazeIO
), or your umask is weird. umask controls the default user permissions on new files, and if you modified it from the default, it might wreak havoc. The default umask is 0022
for most systems, I suggest it be left there unless you know what will happen. I don't have any other idea why you might be missing the exec bit.
Upvotes: 2