当前位置:网站首页>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
边栏推荐
- Rocky basics shell script Basics
- Data center: started in Alibaba and started in Daas
- Vim: extend the semantic analysis function of YCM for the third-party library of C language
- Three tips for finding the latest trends on tiktok
- Linked list - 24. Exchange nodes in the linked list in pairs
- Practice 4-6 number guessing game (15 points)
- Seven data show the impact of tiktok's combination of payment and organic content
- 科目1-2
- Houdini notes
- Account 1-3
猜你喜欢

如何通过NFT GO,来简要判断、分析NFT市场?
![[FFH] websocket practice of real-time chat room](/img/9a/ffd31fe8783804d40edeca515cc96c.png)
[FFH] websocket practice of real-time chat room

唐宇迪opencv-背景建模

Developing ebpf program with go language

The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"

Using OpenCV to do a simple face recognition
![[translation] integration challenges in microservice architecture using grpc and rest](/img/88/53f4c2061b538b3201475ba51449ff.jpg)
[translation] integration challenges in microservice architecture using grpc and rest
![[FFH] openharmony gnawing paper growth plan -- Application of cjson in traditional c/s model](/img/a5/a8f4371a83fbd38c40aa7ba56a36d3.png)
[FFH] openharmony gnawing paper growth plan -- Application of cjson in traditional c/s model

Description of MATLAB functions

Protocol buffers 的问题和滥用
随机推荐
Read write lock, shared lock, exclusive lock
Publish your own library on NPM
Attack and defense world ----- confusion1
Un7.22: how to upload videos and pictures simultaneously with the ruoyi framework in idea and vs Code?
Gnuplot software learning notes
代码随想录笔记_链表_25K个一组翻转链表
Account 1-2
SQL 优化原则
Wildcards in MySQL like statements: percent, underscore, and escape
链表——24. 两两交换链表中的节点
Virtual machine terminator terminal terminator installation tutorial
Getting started with sorting - insert sorting and Hill sorting
Scheme and software analysis of dual computer hot standby system "suggestions collection"
Vim: extend the semantic analysis function of YCM for the third-party library of C language
剑指 Offer II 024. 反转链表
Introduction to common ansible modules
xtrabackup 实现mysql的全量备份与增量备份
How to judge and analyze NFT market briefly through NFT go?
C # briefly describe the application of Richter's replacement principle
Data center: started in Alibaba and started in Daas