An accidental error has aroused awareness of gcc and g ++.

Source: Internet
Author: User

The Code was compiled on linux for a long time. Recently, the experiment behind this paper must be completed in linux, so you have to pick up the programming on linux again. As before, write


[Cpp]
# Include <iostream>
Using namespace std;

# Include <iostream>
Using namespace std;
Then write the main function. Then compile gcc test. cpp-o test1.out, the problem occurs char. cpp :(. text + 0x4d): Undefined reference to 'std: cout'. No, the Referenced File Box namespace is opposite. Is the newly installed system crashed? No, just now several programs have been successfully run. I have no idea how to solve the problem, and I have been searching for problems in the program. I have never found the crux of the problem, and then returned to the terminal. Suddenly, I found that the commands compiled earlier were not like this. In this world, there are more than gcc and g ++. Then g ++ test. cpp-o test1.out. The compilation is successful immediately.

This reminds me of the curiosity. What is gcc? We can see that gcc is a compilation-related command. Otherwise, no std: cout errors will be prompted, but why can't he identify std: cout? What is its relationship with g ++? With these questions, I have a preliminary understanding of gcc and g ++. The following is my summary:

GCC (GNU Compiler Collection, GNU Compiler Collection) is a programming language Compiler developed by GNU. It is used by most Unix-like operating systems (such as Linux, BSD, and Mac OS X) adopted as a standard compiler, GCC is also applicable to Microsoft Windows. Originally, it could only deal with C language. GCC quickly expanded and became able to process C ++. Later, it also became able to process Fortran, Pascal, Objective-C, Java, and Ada and other languages.

G ++ is a c ++ compiler in linux. It takes four steps to compile a program.

1. pre-process and generate the. I file
2. Convert the pre-processed files into assembly languages to generate file. s.
3. a. o file is generated by means of compilation into the target code (machine code ).

4. Connect the target code to generate an executable program

But from the above process, we still cannot solve our doubts. Why is the compilation error mentioned at the beginning of the article? The gcc command cannot be automatically connected to the library used by the C ++ program.

Based on this, g ++ is usually used to complete the link. For the sake of unification, g ++ is used to compile/link all.

 

 

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.