Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Embedded C language compiler

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Embedded C language Compiler 1.1 GCC and gcc

The difference between the above two:

GCC (GUN Compiler Colletion) means that the GUN compiler collection contains many languages to get compilers such as C (gcc), C++ (Gmail +), Java (jdk), D (gdc), etc.

Gcc refers to a simple C language compiler.

Contemporary embedded development is different from traditional embedded development, the improvement of hardware performance makes it more and more close to desktop development, the use of more and more diverse development languages, kernel and driver development using C language, application development using gcc/g++/gdc and so on.

1.2 Cross compilation

Two development modes:

a. Non-embedded development: a (class) machine writes (source code), compiles the executable program, and publishes it to A (class) machine to run.

b. Embedded development: a (class) machine compiles (source code), compiles the executable program, and releases it to B (class) machine to run.

Why use cross-compilation

Due to limited resources, embedded products can not be programmed directly on embedded products, so they choose to write and compile the source code on the PC host, and finally generate programs that run on embedded devices.

Cross-compilation can use high-performance machines to develop software for low-performance machines (including bare metal software, system-level and application-level software).

Cross-compilation features:

A dedicated cross-compilation tool chain must be used. Because the executable program cannot be debugged locally, we must cooperate with certain means (special debugger, JTAG debugger, USB download, serial port download, SD startup, network sharing, etc.) to load the executable program on the target embedded device to run and debug.

How does gcc cross-compile?

Configure the compilation tool chain of the target host (such as arm-linux), and configure the specific version of the tool chain.

Select the corresponding version of the tool chain according to the specific object code

Correct use of special compilation options for hardware architecture

Embedded development environment for large enterprises:

1.3 compilation process

The compiler we usually refer to actually refers to the generalized compiler, which consists of the following four parts:

The entire compilation process is shown below:

The preprocessor completes the work of expanding the header file in place, replacing the macro definition and deleting comments.

Compiler (in a narrow sense): complete the translation of variable files from various languages to the target platform.

Assembler: compiles the platform to avoid that file into the final binary file (.O file)

Linker: the final binary file according to the contents of the connection script, the link is called the most executable file Linux for the elf file.

The whole process: source code. C-> (preprocessing)-> preprocessed. I source file-> (compilation)-> assembly file .s-> (assembly)-> object file .o-> (link)-> elf executable program

1.4 multilingual mixed development

The advantage of the common development method in multi-language mixed development lies in saving manpower cost and improving development efficiency.

Method 1: unification of assembly files on the target platform

Industry case:

Method 2: unify the binary files of the target platform

Industry case:

Method 3: using inter-process communication for collaboration

Industry case:

1.5 gcc compilation options

Preprocessing instruction: gcc-E file.c-o file.i

Compile instruction: gcc-S file.i-o file.s

Assembly instruction: gcc-c file.s-o file.o

Generate the mapping file: gcc test.c-Wl,-Map=test.map (note that there is no space after the comma)

Macro definition: gcc test.c-D 'TEST= "PENGCHAO"' gcc test.c-D TEST=110

Get the system header file path; gcc-v file.c

Get the complete dependency of the target: gcc-M test.c

Get the partial dependency of the target: gcc-MM test.c

Work out the search path for library files and library files

-L instruction library file search path

-l specify 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 to see what symbols are in an .a file.

Ldd command: the function is to parse out which shared libraries are used by a program before it is executed, and to see if these shared libraries can be found and parsed (to determine whether the program can be executed correctly).

Note: the runtime of the dynamic link library needs to be loaded (when the runtime environment executes the test program, it finds that he has dynamically linked libfunc.so, so he will go to the fixed directory (/ user/lib) and try to load libfunc.so. If the load fails, it will print: error while loading shared libraries: libfunc.so: cannot open shared object file: No such file or directory

Solution:

a. Copy dynamic library files to the system library file directory (not recommended)

b. Export the directory where the dynamic library file is located to the environment variable LD_LIBRARY_PATH,export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_name

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report