Makefile.o help ... allowed
I have the following makefile for my program. It creates program.o file, but when I try to run it
./program.o
I am getting the following error:
./statsh.o: Permission denied.
Any ideas why this might be happening?
HEADERS = statsh.h functions.h
default: statsh
statsh.o: statsh.c $(HEADERS)
gcc -c statsh.c -o statsh.o
statsh: statsh.o
gcc statsh.o -o statsh
clean:
-rm -f statsh.o
-rm -f statsh
source to share
The file .o
is only a temporary product. It contains the machine code generated by the compiler for a single compilation unit (basically the file .c
here). However, this file is not meant to be executed - and as you already discovered, it actually cannot be executed.
The make file creates the target file statsh
. This is the one you want to accomplish. It contains code from statsh.o
, as well as library routines, etc. It is created by your makefile according to the rule
statsh: statsh.o
gcc statsh.o -o statsh
which calls GCC to have the binder / binder combine the fragments and construct the target program.
source to share