Embedded C language Compiler

Source: Internet
Author: User

1. Embedded C language Compiler 1.1 GCC and GCC

The difference between the two:
GCC (Gun Compiler colletion), refers to the gun compiler collection contains many languages to get compilers such as C language (GCC), C + + (g++), Java language (JDK), D language (GDC), etc.
GCC refers to a simple C language compiler
Contemporary embedded development has been different from the traditional embedded development, the hardware performance has become more and more close to desktop development, the use of development language is more and more diverse, kernel and driver development using C language, application development using GCC/G++/GDC and so on.

1.2 Cross-compiling

Two modes of development:
A. Non-embedded development: A (Class) machine written (source code), compiled executable program, published to A (class) machine run.
B. Embedded development: A (Class) machine written (source code), compiled executable program, published to the B (Class) machine run.
Why use cross-compilation
Embedded products because of limited resources, can not directly in the embedded product programming, so choose to write and compile the source code on the PC host, and ultimately generate the program running on the embedded device.
Cross-compiling enables the development of software for low-performance machines (including bare-metal software, system-level and application-level software) with high-performance machines
Cross-compiling features:
You must use a dedicated cross-compilation toolchain. Because the executable program cannot run debugging locally, the executable program must be loaded into the target embedded device to run and debug with certain means (dedicated debugger, JTAG debugger, usb download, serial download, SD boot, network share, etc.).
How does gcc cross-compile?
Configure the target host's compilation toolchain (such as Arm-linux) to configure the specific version of the toolchain.
Select the appropriate tool chain version according to the specific target code
Proper use of special compilation options for hardware architectures
Large Enterprise embedded development environment:

1.3 Compilation process

The compiler that we typically refer to is actually a generalized compiler that contains the following four parts:

The entire compilation process looks like the following:

Preprocessor Completion: Header file expansion in place, macro definition substitution, comment deletion work.
Compiler (in narrow sense): complete the translation of the variable files of various languages to the target platform.
Assembler: The platform avoids that file compiled into the final binary file (. o file)
Linker: The final binaries follow the contents of the connection script, and the link is called the most executable file in Linux for elf files.
The whole process: source .c-> (preprocessing), preprocessed. I source file--(compile), assembly file. S-> (assembly), Target file .o-> (link)->elf executable

1.4 Multi-language hybrid development

The common development method in the development of multi-language mixed development is the advantage of saving manpower cost and improving development efficiency.
Mode one: Unification of the target platform assembly files

Industry Case:

Mode two: Unification of the target platform binary files

Industry Case:

Method Three: Using interprocess communication for collaboration

Industry Case:

1.5 gcc compilation options

Pre-processing directive: GCC-E File.c-o FILE.I
compiler directive: Gcc-s file.i-o FILE.S
Assembly instructions: Gcc-c File.s-o FILE.O

Generate Map File: gcc Test.c-wl,-map=test.map (note that there are no spaces after commas)
Macro definition: gcc test.c-d ' test= "Pengchao" ' gcc test.c-d test=110
Gets the system header file path; Gcc-v file.c

Get the full dependency of the target: Gcc-m test.c
Get a partial dependency on a target: gcc-mm test.c

Create a search path for library files and library files
-L Instruction library file search path
-l Specifies the library file name
GCC test.c-l-lfunc

Static Library Generation command: AR-RC libfunc.a FUNC.O
Dynamic Library Generation command: GCC func.c-o func.o-c-fpic
Gcc-o libfunc.so func.o-shared
The NM command is also useful, and it can be used to see which symbols are in a. a file.
LDD command: The function is to parse out which shared libraries the program uses before executing a program that uses the shared library, and to see if the shared libraries can be found and parsed (to determine if the program executes correctly).
Note: The dynamic link library runtime needs to be loaded (the runtime environment discovers that he dynamically linked the libfunc.so when executing the test program, and will then go to the fixed directory (/user/lib) to attempt to load the libfunc.so if the load fails: Error while Loading shared Libraries:libfunc.so:cannot Open Shared object file:no such file or directory
Workaround: Copy the dynamic library file to the system library file directory (not recommended)
Export the directory where the dynamic library files are located to the environment variable Ld_library_path

Embedded C language Compiler

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.