当前位置:网站首页>Makefile variables and dynamic library static library
Makefile variables and dynamic library static library
2022-07-24 09:11:00 【Slag horse】
One 、Makefile Variable
1. Makefile Predefined variables of
| Variable name | meaning |
|---|---|
| AR | Function library packer , You can create a static library .a file . The default is ar |
| AS | assembler , The default is as |
| CC | C compiler , Default gcc |
| CXX | C++ compiler , Default g++ |
| CPP | C The preprocessor of the program , The default is $(CC) -E |
| RM | The delete command , The default is rm -f |
| ARFLAGS | perform AR Command line arguments for the command , Default rv |
| ASFLAGS | Assembler AS Command line parameters of ( Specify clearly .s or .S When you file ) |
| CFLAGS | perform CC Compiler command line arguments ( compile .c Source file options ) |
| CXXFLAGS | perform g++ Compiler command line arguments ( compile .cpp Source file options ) |
2. Makefile Automation variables of
| Variable name | meaning | remarks |
|---|---|---|
| @ ( file name ) | The full name of the target representing the rule in which it is located | |
| % ( file name ) | A member name of the static library file that represents the rule it is in | |
| < ( file name ) | Represents the first full name of the dependency list of the rule in which it is located | |
| * ( file name ) | In pattern rules and static pattern rules , Stands for stem | Stem time target mode ”%” Say the representative part . When the file name exists in the directory , Stems can also contain directories |
| ? ( File list ) | List of dependent files whose timestamp is newer than the target file , Separate with spaces | |
| ^ ( File list ) | Represents the dependency list of the rule in which it is located | The same file cannot be repeated |
| + ( File list ) | Represents the dependency list of the rule in which it is located | The same file can be repeated , Mainly used in program linking , The cross reference place of the Library |
3. Makefile A variant of the automation variable
| Variable name | meaning | remarks |
|---|---|---|
| @D | Represents the directory part of the target file ( Remove the last slash in the directory section ) | If $ @ yes dir/foo.o, that $(@D) The value of is dir; If [email protected] There are slashes , Its value is the current directory (.); Notice how it relates to functions dir The difference between |
| @F | The part of the full file name of the target file other than the directory ( Actual filename ) | If $ @ yes dir/foo.o, that $ (@F) Namely foo.o; $ (@F) It's equivalent to a function $(notdir [email protected]) |
| *D | Represents the directory part in the target stem | |
| *F | Represents the file name part in the target stem | |
| %D | When archive(member) When the formal static library is the target , Table library file members member The directory part of the name | Only on archive(member) Formal rule objectives are valid |
| %F | When archive(member) When the formal static library is the target , Table library file members member The file name part of the name | Only on archive(member) Formal rule objectives are valid |
| <D | Represents the directory part of the first dependent file in the rule | |
| <F | Represents the file name part of the first dependent file in the rule | |
| ^D | Represents the directory part of all dependent files | The same file cannot be repeated |
| ^F | Represents the file name part of all dependent files | The same file cannot be repeated |
| +D | Represents the directory part of all dependent files | The same file can be repeated |
| +F | Represents the file name part of all dependent files | The same file can be repeated |
| ?D | Represents the directory part of the updated dependent file | |
| ?F | Represents the file name part of the updated dependent file |
4. Makefile Operation and use of
# Execute specified Makefile Almake yes makefile The name of
$ make -f ALmake
$ make --file Almake
$ make --makefile Almake
$ make TARGET # Specify the ultimate goal
# Force the reconstruction of targets in all rules
$ make -B
$ make -always-make
# Appoint makefile The path of
$ make -C dir/
$ make --directory=dir/
# GNU-autotools Tools ( automation makefile)
# GNU Trilogy of software installation
$ ./configure
$ make
$ make install
Two 、 Dynamic and static libraries
1. Understanding of static library and dynamic library
- Static library :Linux With .a A file with a suffix name (win Of lib file )
Static library in gcc The link phase of is integrated into an executable program . Even if the library is deleted , The program can still run successfully . But it's big .
Copy the static library loader when the program is loaded , So the volume is large . - Dynamic library :Linux With .so A file with a suffix (win Of dll file )
The dynamic library does not belong to any program , Any program can share this library , When the program is running , Only link library . Small volume . - Linux Rules for dynamic libraries in the naming system of
libname.so.x.y.z
lib: Fixed representation Library name: Library name so: Fixed suffix x: The major version number y: Sub version number z: Release number
The main version is incompatible during version upgrade ( The main version number is different )
Next version update software , Keep the original program , Add functionality ( Version numbers are downward compatible )
Release performance changes , Program optimization ;( Mutual compatibility )
2. The creation and use of static library (ar command )
# ar Common parameters of
$ ar -ctr libtest.a *.o # Put all... In the current directory .o Files are packaged into static libraries libtest.a
#ar Parameters of
# -r Insert the file into the library file , If it already exists, replace ;
# -t View all packaged .o file
# -c Representation creation ,create
$ gcc main.c libtest.a -o main # Use static libraries
3. The creation and use of dynamic library
$ gcc -fPIC -shared *.c -o libtest.so # Create a dynamic library
# -fPIC Means to generate independent code PIC Tell the compiler to generate location independent code , That is, the memory is not fixed .
# -shared Means to generate a shared dynamic library
$ gcc main.c ./libtest.so -o main -I ./inc # Link dynamic library to generate execution file main, but main The dynamic library must exist when executing .
# Dynamic library defaults to real system lib In looking for , The generated dynamic library can be used in the system lib in ; You can also add $LD_LIBRARY_PATH Environment variables of can also be added to this directory .
# Add environment variables export LD_LIBRARY_PATH=/home/gec/Linux/ku:$LD_LIBRARY_PATH
# /home/gec/lib: Library file path ( The path can be specified according to your own needs );
# Be careful : When encapsulating the dynamic library, the function corresponds to the header file ; Dynamic library should exist ; Dynamic library environment
边栏推荐
- [example of URDF exercise based on ROS] use of four wheeled robot and camera
- How should tiktok shop cooperate with live broadcast in the background?
- How to judge and analyze NFT market briefly through NFT go?
- 【我的创作一周年纪念日】爱情是需要被纪念的,创作也是
- Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
- Promise基础总结
- Tang Yudi opencv background modeling
- (5) Cloud integrated gateway gateway +swagger documentation tool
- Using OpenCV to do a simple face recognition
- UE5影视动画渲染MRQ分层学习笔记
猜你喜欢

The detailed process of building discuz forum is easy to understand

Linked list - 19. Delete the penultimate node of the linked list

链表——24. 两两交换链表中的节点

Detailed sequence traversal of leetcode102 binary tree

科目1-2

我们说的组件自定义事件到底是什么?

Configuration of uni app page.json title bar

Developing ebpf program with go language

Opencv Chinese document 4.0.0 learning notes (updating...)

Tongxin UOS developer account has supported uploading the HAP package format of Hongmeng application
随机推荐
Asyncdata cross domain error after nuxt route switching
Tang Yudi opencv background modeling
03_ UE4 advanced_ illumination
Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
Using OpenCV to do a simple face recognition
One year after I came to Ali, I ushered in my first job change
Scheme and software analysis of dual computer hot standby system "suggestions collection"
[FFH] openharmony gnawing paper growth plan -- Application of cjson in traditional c/s model
TCP triple handshake connection combing
使用分区的优点
[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)
One click openstack single point mode environment deployment - preliminary construction
Android system security - 5.3-apk V2 signature introduction
Linked list - 19. Delete the penultimate node of the linked list
Opencv Chinese document 4.0.0 learning notes (updating...)
Promise basic summary
Houdini 笔记
DSP development, using CCS software to establish engineering and burning
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Assignment operator (geritilent software - Jiuye training)