Reputation: 907
I try to compile and execute a c-written program and I get the error message written in the topic.
I am logged in over SSH, go to the directory where my method is, and compile it with:
gcc -o exec -c main.c
Which generates the "exec" file. Then I put the rights:
chmod u+x exec
And when I try to run it with ./exec i get the error message :S.. What do I miss here :S??
Upvotes: 2
Views: 460
Reputation: 148
You should compile your main.c file as gcc -o exec main.c as -c option is for
-c Compile or assemble the source files, but do not link. The linking
stage simply is not done. The ultimate output is in the form of an
object file for each source file.
By default, the object file name for a source file is made by
replacing the suffix .c, .i, .s, etc., with .o.
Upvotes: 0
Reputation: 41036
Gcc with flag -c
compiles to an object, and not to a runnable binary. If you want to binary, omit this flag.
Change to:
gcc -o exec main.c
Upvotes: 3
Reputation: 409364
The problem is the -c
option, which tells gcc
to generate an object file. Object files are files which can be used with the linker to create the final executable program.
So the solution is to either drop the -c
option, in which case gcc
will generate a temporary object file (which it then deletes) and do linking in one step. Or you link separately in a separate step after compiling:
$ gcc -o main.o -c main.c
$ gcc -o exec main.o
Upvotes: 2