Embedded C language Compiler (v)

Source: Internet
Author: User

We often see in the development of embedded gcc and gcc, then what is the difference between them? GCC (GNU Compile Collection) refers to theGNU Compiler collection, compiler with many languages, such as C, C + +, Java, D, objective-c, etc., while GCC is specificallyC language compiler in GCC。 So what is the relationship between GCC and embedded? Most embedded operating systems are based on GCC for source code compilation, such as Linux, VxWorks, and Android. In the actual development, the kernel related development uses the GCC, but the application development uses GCC/G++/GDC and so on.

Let's take a look at an embedded development of high-end atmospheric-grade words: cross-compiling. So why would there be cross-compiling? In the past, embedded devices are often resource-constrained, and it is not possible to directly program the processor directly on the embedded system. The solution at this point is to compile the source code on the development host (PC) and eventually generate the executable program for the target host (embedded device). How does gcc cross-compile? 1. Configure the target host's compilation tool chain (such as Arm-linux), 2. Configure the specific version of the toolchain: Select the appropriate toolchain version according to the specific target code, and use the special compilation options about the hardware system correctly . Let's take a look at the embedded development environment for large enterprises, as follows

This server cluster is equivalent to the internal server of our own company, and version control refers to the new version generated by the original version after some of our code has been modified, for each version of the control. File tracking refers to the server can see that part of the code is specific to which person to rewrite, can be specific to the file and part of the code. Let's see what the compiler is, as follows

The compiler actually consists of a preprocessing period, a compiler, a assembler, and a linker. What we call a compiler to compile the generated file, at this point the compiler refers to a wide range of compilers. Then the narrow sense of the compiler refers to the production of a language we hear the compiler, at this time the compiler refers to the specific language translated into the target platform code just. Let's take a look at how a. c file is compiled into an. o file, as shown in the following steps

We see that it's not what we think. c files are directly compiled into an. o executable file, but it takes so many steps to generate the final executables. So now we're extending a question, how do we understand "multi-lingual mixed development"? We may hear a mixed-language development of multiple languages at ordinary times, which is a mix of several languages for an application development. So why would this hybrid approach be developed? For example, a project is done by C + +, but some parts of it can be done in C #, at a time when the number of people proficient in C + + is very small (the corresponding salary is very high), and C # Engineers by a lot, we can need two proficient C + + engineers and several C # engineers to work together to complete the project, Achieve the effect of completing this project with minimal expense. Or if everyone in your group is good at different languages, you can take this hybrid approach in order to maximize the efficiency of everyone. Let's take a look at some of the ways in which multi-lingual hybrid development

Way One , as follows

This approach is achieved through the assembly of several languages to obtain the target Platform assembly language, and then by the target platform assembler unified chain delivered into an executable program . The industry's typical case is the. NET Framework, which is developed by a mix of C #, C + +, and VB, as follows


mode two , as follows

It is generated by the respective language of the corresponding library and then through the target platform linker Unified link to the executable program . The typical case is QQ, as follows

Way three , as follows

It is executed by the respective compiler, Mr. EXE, and then through the Interprocess communication protocol to generate an executable program . Industry case: Eclipse, as follows

Let's take a look at GCC key compilation options.

gcc key compilation option one :a> preprocessing directives are:gcc-e file.c-o file.i; b > Compile directives:gcc-sfile.i-o file.s;c> Assembly instructions:gcc-c file.s-o file.o.

Let's see what the effect is.


Func.h Source

#include <stdio.h>void func () {#ifdef test printf ("test =%s\n", test); #endif return;}


TEST.C Source

#include <stdio.h> #include "func.h" int g_global = 0;int G_test = 1;int main (int argc, char *argv[]) {func ();    printf ("&g_global =%p\n", &g_global);    printf ("&g_test =%p\n", &g_test);    printf ("&func =%p\n", &func);        printf ("&main =%p\n", &main); return 0;}

Let's take a look at the preprocessing effect, open the Test.i file and look at the beginning of this

The first line of 1 indicates that the following content is the content of the test.c file, and the following is the inclusion of some header files.

# 2 "test.c" 2 means that the inclusion of the TEST.C header file has ended, # 1 "func.h" 1 represents the beginning of func.h related content. Finally, the contents of the main function of the test.c file. Here's a look at the. s file generated by the compilation instructions

Are some of the generated assembly commands. Here's a look at the final assembly instructions to generate the. o File

gcc key compilation option two :a> build map file:gcc-wi,-map=test.map file.c;b> macro definition:gcc-d ' test= ' test ' file.c< /c3>;c> gets the system header file path:gcc-v file.c.

gcc key compilation option three : generate dependencies. A> gets the full dependency of the target:gcc-m test.c;b> Gets a partial dependency of the target:gcc-mm test.c.

Let's take a look at how the effects of-M and-mm are respectively, as follows

We see that there are so many header files, which are formatted similar to the relationship between the targets and dependencies in makefile. The dependencies are test.c and numerous header files as well as the func.h header files that we ourselves contain. And look at the effect of-mm.

The effect we see-mm is that it relies on test.c and func.h, and there are no other header files.

gcc key compilation options four : Specifies the library file and library file search path. The -l option is the search path for the specified library file, and-L is the specified library file , such as gcc test.c-l-lfunc.


FUNC.C Source

#include <stdio.h>void func () {#ifdef test printf ("test =%s\n", test); #endif return;}


TEST.C Source

#include <stdio.h>int G_global = 0;int g_test = 1;int main (int argc, char *argv[]) {func ();    printf ("&g_global =%p\n", &g_global);    printf ("&g_test =%p\n", &g_test);    printf ("&func =%p\n", &func);        printf ("&main =%p\n", &main); return 0;}

The compilation results are as follows

We see the AR CRS command to package the FUNC.O into a libfunc.a file, and then the GCC test.c-l.-lfunc command to generate the executable program a.out ( where the point after-L is represented in the current directory ).

Embedded C language Compiler (v)

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.