Running the complier from the Command line
CC prog1.cc
For Windows, it would generate the executable file named Prog1.exe
For UNIX, it tends-put their executables in files named a.out
Remarks:
About CC and GCC
Cc refers to the C compiler on UNIX while GCC comes from Linux, which is the abbreviation of the GNU compiler collection. Notice that GCC are a collection of compilers (not only related to C and C + +).
Actually, in Linux, CC is the same as GCC. CC is just a soft link of GCC to make it easy to transfer the project from UNIX to Linux.
About GCC and g++
GCC regards file with suffix. C as C program while g++ regards it as C + + program. CPP is regarded as C + + program for both commands.
In the compiling, g++ would invoke GCC command. Because GCC can not be automatically connect to the libraries and while g++ can. So we usually use g++ instead of GCC.
In my Mac, when I enter GCC HelloWorld.cpp, it would throw a lot of error message for undefined symbols, which would not hap Pen If you use g++ command.
The program in HelloWorld are very easy.
#include <iostream>
using namespace Std;
int main (int argc, const char * argv[]) {
Insert code here ...
Std::cout << "Hello, world!\n";
return 0;
Reference: http://www.cnblogs.com/xiedan/archive/2009/10/25/1589462.html
After compiling, we can directly run the executable file:
For Windows, we just enter "Prog1"
For Unix, we should use./a.out. (./Indicates the file is in the current directory)
In my Mac, the output is as below:
181-39:cppstudy luke$./a.out
Hello, world!.
The value returnd from main was accessed in a system-dependent manner. On both UNIX and Windows systems, after executing the program, you must issue an appropriate echo command echo $?. In Windows, we write Echo%errorlevel%
In my Mac, the output of the echo $? command is as below:
181-39:cppstudy luke$ echo $?
0
Zero is the return value of the main function.
If you use g++-o prog1 prog1.cc, it'll generate an executable file named Prog1 instead of A.out. For example, on my Mac, when I enter g++-o lukewang main.cpp, then the it'll generate a file named Lukewang, you can us E./lukewang to run the file. The-o is an argument (parameter) to the compiler, which can isn't be omitted.
Exercise 1.2:if The return value is-1, the result of command echo $? is 255.
Remarks: I use GDB as the debugging tool.
Here are the reference about GDB and GCC.
http://blog.163.com/[email protected]/blog/static/109968875201292625126644/
Running the complier from the Command line