Running the complier from the Command Line
2014-12-08 22:11
169 查看
Running the complier from the Command Line
CC prog1.cc
For windows, it will generate the executable file named prog1.exe
For UNIX, it tends to put their executables in files named a.out
Remarks:
About cc and gcc
Cc refers to the C compiler in UNIX while gcc comes from Linux, which is the abbreviation of GNU compiler collection. Notice that gcc is 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++ will invoke gcc command. Because gcc can not automatically connect to the libraries, while g++ can. So we usually use g++ instead of gcc.
In my Mac, when I enter gcc HelloWorld.cpp, it will throw a lot of error message for undefined symbols, which will not happen if you use g++ command.
The program in HelloWorld is 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: /article/5835362.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 is 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 will generate an executable file named prog1 instead of a.out. For example, in my Mac, when I enter g++ -o lukewang main.cpp, then the it will generate a file named lukewang, you can use ./lukewang to run the file. The -o is an argument(参数) to the compiler, which can not 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 is the reference about gdb and gcc.
http://blog.163.com/liuqiang_mail@126/blog/static/109968875201292625126644/
CC prog1.cc
For windows, it will generate the executable file named prog1.exe
For UNIX, it tends to put their executables in files named a.out
Remarks:
About cc and gcc
Cc refers to the C compiler in UNIX while gcc comes from Linux, which is the abbreviation of GNU compiler collection. Notice that gcc is 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++ will invoke gcc command. Because gcc can not automatically connect to the libraries, while g++ can. So we usually use g++ instead of gcc.
In my Mac, when I enter gcc HelloWorld.cpp, it will throw a lot of error message for undefined symbols, which will not happen if you use g++ command.
The program in HelloWorld is 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: /article/5835362.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 is 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 will generate an executable file named prog1 instead of a.out. For example, in my Mac, when I enter g++ -o lukewang main.cpp, then the it will generate a file named lukewang, you can use ./lukewang to run the file. The -o is an argument(参数) to the compiler, which can not 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 is the reference about gdb and gcc.
http://blog.163.com/liuqiang_mail@126/blog/static/109968875201292625126644/
相关文章推荐
- Xcode4: Running Application Tests From The Command Line in iOS
- Running the Compiler from the Command Line
- Running DataVision from the Command Line
- Microsoft SQL Reporting Services – Running a Report from the Command Line
- Running scripts from the command line with idascript
- Running Your iOS App in the Simulator From The Command Line
- Running a command on every machine in your domain from the command line
- Create & delete user accounts from the command line on Mac OS X
- Managing Projects from the Command Line(android官网文档)
- Building Xcode iOS projects and creating *.ipa file from the command line
- How to easily open files and URLs from the command line
- OpenSSL: Generating an RSA Key From the Command Line
- `Gtk-WARNING **: Locale not supported by C library. ` when starting apps from the commandline
- Managing Windows Programs from the Command Line: Tasklist
- Creating SQL procedures from the command line
- Lab01 Manipulating text files from the command line
- Run iOS Simulator from the Command Line (runsim)
- Enable/disable a device from the command line
- How to download files from the Linux command line
- IAR Build from the command line 环境变量设置