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