Linux C/C ++ compilation and linux Compilation

Source: Internet
Author: User

Linux C/C ++ compilation and linux Compilation

I have compiled C in Linux before, but I have not compiled C ++. I learned a little about it today.

Brief Introduction

The most important compilation tool in linux is GCC. GCC is the gnu c and C ++ compilers. In fact, GCC can compile three languages: C, C ++, and ObjectC (I have never tried OC) (an object-oriented extension of C ). The gcc command can be used to compile and connect the C and C ++ source programs at the same time.

C Compilation:

For GCC installation instructions, refer to my previous documents.

If you have more than two C source files, you can easily compile, connect, and generate executable files using GCC.

$ Gcc-o exename main. c file. c file2.c

Exename indicates the name of the executable file to be generated, followed by your C program source file;

For more information about C compilation, see my first LinuxC program.

C ++ Compilation

GCC can be used to compile both C and C ++ programs. Generally, the C compiler uses the extension of the source file to determine whether it is a C program or a C ++ program. In linux, the extension of the C source file is. c, and the extension of the C ++ source file is. C or. cpp. However, the gcc command can only compile the C ++ source file, but cannot automatically connect to the library used by the C ++ program. Therefore, the g ++ command is usually used to compile and connect the C ++ program. The program automatically calls gcc for compilation.

$ G ++-o exename main. cpp

Exename is still the name of the executable program, followed by the source file of the program.

References: blog posts

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.