c - Why am I not able to produce a "Hello World" executable using gcc? -
i'm trying compile first "hello world" application using gcc (build-on clang , stand-alone gcc-4.9.2) without success:
os version os x yosemite 10.10.2.
i'm using following code (main.c):
#include <stdlib.h> #include <stdio.h> int main (){ printf("hello world!"); getchar(); return 0; }
then compile in terminal command (clang shipped xcode):
gcc -o hello -c main.c
as result got following error whe running compiled hello
file:
mbp-andrii:ctest andrii$ gcc -o hello -c main.c mbp-andrii:ctest andrii$ hello -bash: /users/andrii/avrtest/ctest/hello: permission denied
if change permissions hello
file 777
, new error again:
mbp-andrii:ctest andrii$ chmod 777 hello mbp-andrii:ctest andrii$ hello killed: 9 mbp-andrii:ctest andrii$
the same thing happens stand-alone gcc-4.9.2.
i guess might related output binary format or missing flags compiler.
remove -c
command you're using compile application.
the -c
tells compiler compile , assemble not link. not creating application when using -c
.
see gcc manual:
-c
compile or assemble source files, not link. linking stage not done. ultimate output in form of object file each source file.
by default, object file name source file made replacing suffix ‘.c’, ‘.i’, ‘.s’, etc., ‘.o’.
unrecognized input files, not requiring compilation or assembly, ignored.
Comments
Post a Comment