I'm a beginner to use Linux OS. I don't know how to compile and run a C program in Linux. Can anyone help one?
I'm a beginner to use Linux OS. I don't know how to compile and run a C program in Linux. Can anyone help one?
C++: g++ -o executable source.cc
C: gcc -o executable source.c
If you don't specify the object file with -o, it defaults to a.out.
For more information on all of the different options: man gcc
Mark Loeser
http://www.halcy0n.com
Can you explain more about what means of 'If you don't specify the object file with -o, it defaults to a.out.'?
Also, if i have a file to pass in the program, how can I do this?
The object file is the program. If you just say g++ source.cpp, it will compile the code and make a.out the executable. On the other hand, if you specify one, it will compile and make it.
g++ -o exec source.cpp, will result in making a file called "exec" as the compiled version of source.cpp.
As for the file issue, I believe http://faq.cprogramming.com/cgi-bin/...&id=1043284392 should help.
Mark Loeser
http://www.halcy0n.com
Thank you for your reply