(GO) g++ command

Source: Internet
Author: User

GCC & g++ is now the main and most popular C & C + + compiler in GNU.
g++ is a C + + command, with. cpp as the main, for C language suffix generally. c. This is the order for GCC to be replaced. In fact, it doesn't matter.
In fact, the compiler is based on GCC or g++ to determine whether to follow the C standard or C + + standard compile links.


Let's take Test.cpp as an example:

Command: g++ Test.cpp
Features: Generates a file that defaults to A.exe, which includes compilation and linking.
Again the-o command, the-o command indicates the meaning of the output, the gcc/g++ command is very flexible, you do not specify the output file name when the default is generated by the. exe file.
You want to output Test.exe words can be used:g++-o Test.exe Test.cpp. The-o command is the output meaning, which outputs the Test.exe.

gcc/g++ A total of the following steps are required to perform the compilation work:

  1. <span style="font-family: ' Microsoft Yahei '; font-size:16px;" > /*************************
  2. Test.cpp
  3. *************************/
  4. #include <IOSTREAM>
  5. static int t = 1;
  6. #define T 9
  7. using namespace std;
  8. typedef INT Status;
  9. int main ()
  10. {
  11. Status i = 1;
  12. cout << T * I << Endl; //test Cout
  13. return 0;
  14. }</span><span style="font-family: ' Microsoft Yahei '; font-size:18px; ">
  15. </span>




1. Preprocessing, generating. I files [preprocessor CPP]

Command: g++-e Test.cpp > Test.i

Function: Output pre-processing file, Linux under. I is the suffix name. Just activate the preprocessing, this does not generate the file, you need to redirect it to an output file. This step mainly does these things: the substitution of macros, the elimination of annotations, and the finding of relevant library files. Open test.i with the editor will find a lot of code, you just need to see the last part of the change, the preprocessing has done a macro substitution, as well as the elimination of annotations, can be understood as irrelevant code cleanup. The following is the last part of the test.i file, where you can see the substitution of macros and the elimination of annotations.

  1. <span style="font-family: ' Microsoft Yahei '; font-size:16px;" ># 5 "Test.cpp" 2
  2. static int t = 1;
  3. Using namespace std;
  4. typedef INT Status;
  5. int main ()
  6. {
  7. Status i = 1;
  8. cout << 9 * i << Endl;
  9. return 0;
  10. }</span>


2. The preprocessed file is not converted to assembly language, and the file is generated. s[compiler Egcs] command: g++-S Test.cpp
function: Test.s file will be generated, .s file means assembly file, open with editor is assembly instruction.

/span> 3. There is a compilation into the target code (machine code) to generate. o file [assembler as] command: g++-c test.cpp 
features: .O is gcc-generated the target file, unless you are doing compiler and connector debugging development, otherwise open this. O has no meaning. Binary machine code The average person can not read.

/span> 4. Connect the target code to generate an executable program [ Linker LD] command: g++ test.o-l F:\vs2008\VC\include\iostream
function: Integrate the. o file with the required library file link to form an. exe file, which is the executable file. -L is the link, here I write the absolute path, relative to each computer different


You can g++ Test.o-o Test.exe-l F:\vs2008\VC\include\iostream


Write the above to be able to understand how the entire source file becomes an executable file, gcc/g++ is really a force AH (*^__^*)

(GO) g++ command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.