Sinisterly
C compilation! - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.li/Forum-C-C-Obj-C)
+--- Thread: C compilation! (/Thread-C-compilation)



C compilation! - BlueCat - 06-21-2014

Learning C in linux.

The simple hello world.

Code:
#include <stdio.h> main() { printf("Hello, world!\n"); return 0; }

Then why trying to compile it using.

Code:
gcc -o hello.c

It gives an error of
Code:
gcc: fatal error: no inpurt files compileation terminated



RE: C compilation! - The Real Slim Shady - 06-21-2014

well lets look at this command you're running

gcc -o hello.c

gcc -> Now gcc is pretty obvious i guess. thats the name of the compiler

-o -> this is an argument/switch/option/whatever you want to call it. This one tells the compiler what it should save the output/compiled application as on the hard disk. its the output of the compilation you are running

so right now you are telling it to save the gcc output to hello.c

how does the compiler know what to compile? you havent specified the file you want to compile, only the file you want when its done. Its not a mind reader - you need to tell it what file to compile!


RE: C compilation! - alok9shm - 06-21-2014

Use this Command:
Code:
gcc hello.c -o hello

And to run it, just enter the filename:
Code:
hello



RE: C compilation! - chmod - 06-21-2014

As above really, but one more thing you should always make sure that main is of type int
Code:
int main(void)

although it will compile it's considered bad practice.


RE: C compilation! - BlueCat - 06-21-2014

(06-21-2014, 03:16 PM)chmod Wrote: As above really, but one more thing you should always make sure that main is of type int
Code:
int main(void)

although it will compile it's considered bad practice.

I thought
Code:
void

does not work with all compilers?


RE: C compilation! - chmod - 06-21-2014

(06-21-2014, 03:33 PM)BlueCat Wrote:
(06-21-2014, 03:16 PM)chmod Wrote: As above really, but one more thing you should always make sure that main is of type int
Code:
int main(void)

although it will compile it's considered bad practice.

I thought
Code:
void

does not work with all compilers?

void is not strictly required (force of habit) and you should not get any problems using it with gcc or any other compiler, all it means is that the function, in this case main does not take any arguments, however it will still return an integer value (0) so should be of type int.