During my study in the university, I often encountered various programming environment configurations such as GNU GCC /g++, LLVM clang/clang++, Windows Mingw/MSVC and CMake.
This article hopes to clarify the relationships between these terms, which will help you understand the various operations in the various environment configurations and gain a deeper understanding of the program execution itself.
A cliche
Hello World: hello.c
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
Copy the code
And then there’s the usual description:
To get this code to run on Linux, we need to use GCC
- Precompile: precompile hello.c and stdio.h to hello. I
- Compile: Compile hello. I to hello.s
- Assembler: Translate hello.s into machine instruction hello.o (.o object file)
- Link: Link various required libraries and other object files (not required by the hello program) to get the executable hello.out (equivalent to.exe for Windows)
The whole process translates high-level languages into machine languages, and the compiler is one such tool. GCC can complete the entire process from precompiling to compiling, assembling, and linking.
However, I don’t see this process when I use Visual Studio and other software, because VS is a highly Integrated Development Environment (IDE), which integrates a code editor, compiler, debugger and graphical user interface. All of the above program compilation and linking is covered in a single build.
The GNU GCC/g + +
First of all, what is GNU? The GNU Project, also known as the Genu Project, was publicly launched by Richard Stallman on September 27, 1983. Its goal is to create a completely free operating system. Because Unix, which started at Bell LABS in 1969, was a commercial operating system.
And Stallman launched one of the goals of the GNU project is “solidarity” prestigous software cooperation and mutual assistance, and to ensure that the GNU software is free to use, copy, modify and release “, all the GNU software have a authorized in the case of any restrictions prohibit others to add the terms of the agreement, all rights to anyone The GNU General Public License (GPL).
Stallman is a pioneer in the open source movement. And his original goal of “creating a completely free operating system” was achieved, namely GNU/Linux, or Linux for short!
Gnu English is supposed to be wildebeest, and so is its avatar.
The Linux kernel was originally written by Linus Torvalds as a hobby while he was a student at the University of Helsinki. The first version was released in 1991 with only 10 million lines of code. In 1992 Linux was combined with other GNU software (including GCC, of course) and the completely free operating system was born.
The logo of Linux is the penguin, because according to the international convention, Antarctica is the common property of all human beings and does not belong to any country in the world. Linux chose the penguin Logo, representing the open source Linux for all mankind.
In addition, Linus Torvalds is undoubtedly one of the greatest programmers in the world, having built GitHub, the world’s largest dating community for programmers.
Back to business: GNU’s GCC/G++
First, GCC/G++ can be viewed as a whole. There is no distinction between GCC and G++, because programming languages have been very complex, and so have compilers. We think of both as GCC, which supports C, C++, and Fortran.
GCC(GNU Compiler Collection) is the representative achievement of GNU movement, and its original intention is to develop a complete Compiler for the free system of GNU.
So, in Linux and even Windows, all kinds of development environment configuration, source code compilation, are inseparable from GCC and g++.
Windows的Mingw/MSVC
MinGW(Minimalist GNUfor Windows), a collection of freely usable and freely distributed Windows-specific header files and import libraries using the GNU toolset, Allows you to generate native Windows applications on the Windows platform without the need for a third party C Runtime library.
Runtime library: A collection of basic functions that support the execution of a program, typically a static library lib or a dynamic library DLL.
MSVC is the third party C runtime library mentioned above: the VC runtime library developed by Microsoft and integrated with the Visual Studio IDE. So we use VS with the MSVC compiler.
As you can see, MinGW and MSVC are both Windows C/C++ compiler support, so you can choose one or the other when configuring your environment.
LLVM的clang/clang++
LLVM and Clang should be known without explanation.
LLVM is a framework system of architecture compilers, written in C++, used to optimize compile-time, link-time, run-time, and idle-time of programs written in any programming language. Keep it open to developers and compatible with existing scripts.
The LLVM program was initiated in 2000 by Dr. Chris Lattner of UIUC University. Chris Lattner joined Apple Inc. in 2006. And committed to the application of LLVM in Apple development system. Apple is also a major funder of the LLVM program.
Currently LLVM has been adopted by Apple IOS development tools, Xilinx Vivado, Facebook, Google and other major companies.
Make/CMake
With the compiler GCC and so on, why make is a build generator is also an old story.
Compiling Hello.c is very simple, just need
$ gcc hello.c
Copy the code
C depends on a.c, b.c, and A.C depends on the library W.lib. Do we need to rewrite the GCC compile command line every time we compile?
As a result, GNU invented the make tool, which can write makefiles to specify specific project build procedures. When the code of a project file changes, we simply need to make again.
However, make still has many disadvantages, such as
- Make is generic for Unix-like systems, but not Windows friendly (cross-platform)
- Make’s simple syntax limits its functionality
- Syntax rules vary from compiler to compiler, and makefile syntax written for GCC will not work for MSVC
So, CMake was born.
CMake is a higher tool than Make. Make writes the corresponding compiler’s makefile for compilation, while CMake writes a separate cmakelist.txt file that selects the appropriate build generator (such as VS or Make) based on the current system environment. Then translate cmakelist.txt into a suitable file, and then call the system compiler to build the project.
THE END
GCC, MSVC and CMake: GCC, MSVC and CMake: GCC, MSVC and CMake
Familiar with Cpp: a machine vision software development engineer for mechanical transcoding