NDK series [12] The compiler clang gcc g ++

1. gcc/g++/clang

Learn to use the basic c / c ++ compiler, it is possible to third frame subsequent transplantation cross-compile a clear understanding of what parameters should be passed.

clang

clang is a C、C++、Object-Clightweight compiler. Based on LLVM(LLVM is a frame system written in C ++ compiler framework, it can be said for the development of a compiler associated libraries)

gcc

GNU Ctranslater. Originally only handle C语言, soon expanded, it becomes possible to deal with C++. (GNU programs, also known as the leather slave program. The goal is to create a completely free operating system)

g++

GNU c++translater

gcc, g ++, clang is the compiler.

  • gcc and g ++ are able to compile c / c ++, but the compiler when different behaviors.
  • clang is also a compiler, compared to gcc, it has to compile faster, smaller, etc compiler output, but some software source code in question because an error occurs when using clang compiler.
  • and clang clang ++ is equivalent to gcc and g ++.

For gcc and g ++:

  1. Suffix for .csource files, gcc use it as a C program, and g ++ as a C ++ program; suffix .cpp, both of which would be seen as c ++ program
  2. g ++ will automatically link c ++ standard library stl, gcc will not
  3. __cplusplus gcc does not define macros, and g ++ will

linux install gcc

apt install build-essential #安装gcc、g++与make

2. compiler process

A C / C ++ files to be pretreated (preprocessing), compiler (compilation), assembler (assembly), and connecting (linking) to become an executable file.

1, pretreatment

​  gcc -E main.c  -o main.i

-EThe role is to allow gcc compiler stops at the end of the pretreatment.

The main treatment include pretreatment stage and define the like. It #include the incoming .h file into a position where #include, the source used to #define for macros replaced with actual string

2, compilation stage

​ gcc -S main.i -o main.s

-SThe end effect is compiled, the compiler generates a compiled file.

At this stage, gcc should first check the specification of the code, syntax errors, etc., to determine the actual work to be done code in check and correct, gcc translate the code into assembly language.

3, the compilation stage

​ gcc -c main.s -o main.o

.S file compilation stage to translate into binary machine instructions file .o, at this stage receives .c, .i, .s files are no problem.

4, the link stage

​ gcc -o main main.s

Link phase, is linked libraries . In main.c does not define "printf" function to implement, and is included in the pre-compiled into the "stdio.h" is also only declare the function. System to achieve these functions are called to do libc.sodynamic library.

Libraries are generally divided into two kinds of static and dynamic libraries

  • Refers to a static library is compiled and linked, all the code library file is added to the executable file, so the resulting files are large, but it is no longer needed at runtime library files. Linux in the suffix ".a".
  • DLL contrast, when you compile and link the code library file is not added to the executable file, but loaded by the runtime library link files during program execution. Linux the suffix ".so", as previously described libc.so is dynamic libraries. gcc default dynamic library at compile time.

Static library to save time: no need to dynamically link code needs to call directly on the internal code

Dynamic libraries to save space: If a dynamic library is called both programs, then the dynamic library requires only memory

Java can only be used directly in a dynamic library without going through the package.

Guess you like

Origin blog.csdn.net/u011077027/article/details/93186271