tags:

views:

230

answers:

1

I have the following makefile for my program. It creates program.o file, but when I try running it

./program.o

I get 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
+2  A: 

The .o file is only a temporary product. It contains the machine code generated by the compiler for a single compilation unit (basically, a .c file here). However, that file is not intended to be executed -- and as you have already discovered, it cannot actually be executed.

The makefile produces the target file statsh. That's the one you want to execute. It contains the code from statsh.o, as well as library routines, etc. It is produced by your makefile by the rule

statsh: statsh.o
    gcc statsh.o -o statsh

which invokes GCC in order to have the linker/binder put the pieces together and construct the target program.

Dirk
you're right..../program worked fine