当前位置:网站首页>GCC compiling dynamic and static libraries
GCC compiling dynamic and static libraries
2022-06-27 12:43:00 【xiongsiyu979】
gcc Common options and dynamic library static library
One 、gcc summary
- compiler (Compiler) hold Source code is converted to other lower level code ( For example, binary code 、 Machine code ), But it won't be executed .
- Interpreter (Interpreter) Will read the source code , And generate instructions directly Let the computer hardware execute , No other code will be output .
- gcc It started as C Linguistic compiler , But later the function was expanded , Become able to support compiling more languages , for example C++、Java、Go、Objective -C etc. , So later gcc It was renamed GNU Compiler Suite (GNU Compiler Collection Compiler collection ).
- gcc The compilation process is based on File suffix To call different compilers
- .c There are four steps to generate an executable file from a file precompile 、 assembly 、 compile 、 link
Two 、gcc Common options
test.c
#include <stdio.h> int main(int argc, char *argv[]) { printf("Hello world!\n"); return 0; }
-E : precompile
gcc -E test.cExecute to precompile , Replace the code text . Output precompiled results to standard output ( It's usually a monitor )

-S : assembly
gcc -S test.cExecution to assembly , Source code to assembly code conversion , Output assembly code (.s file )

-c : compile
gcc -c test.cExecute to compile , Output target file (.o file )


- -o : change gcc Output file name
If you want to use it gcc Generate executable files , Can directly
gcc test.oGenerate executable files a.out,gcc test.o -o testYou can rename the generated executable a.out Designated for us test( from .o The process from file to executable file is actually the process of linking )
-shared And -fPIC: Create a dynamic library
-fPIC:(Position-Independent Code) It works on Compile phase , Tell the compiler to generate Location independent code (.o file )-shared: Will be multiple .o The file is linked into a .so Dynamic library files
Will now print ”Hello world!“ The function of is encapsulated into a function , And will hello.c Make dynamic library and static library respectively , stay test.c Of main() In the static library or dynamic library hello() To print “Hello world!”
hello.h
#ifndef _HELLO_H_ // A defensive statement #define _HELLO_H_ extern int hello(); #endifhello.c
#include <stdio.h> int hello() { printf("Hello world!\n"); return 0; }test.c
#include <stdio.h> #include "hello.h" int main(int argc, char *argv[]) { hello(); return 0; }

- -I( uppercase i): towards gcc Add header file search path to

- -l( Lowercase L): Specify the library to link
- -L: towards gcc China Canada stock in path

Dynamic links require... At run time export Introduce the dynamic library path to the lookup path to link , Static links don't need 
9. -static: Link static libraries


- -w: Turn off the warning
- -Wall: Turn on all warnings
- -g: Generate object code with debug information
边栏推荐
- Interview shock 60: what will cause MySQL index invalidation?
- Hibernate operation Oracle database primary key auto increment
- 【粉丝福利】今天给大家介绍一个白捡钱的方法-可转债,本人亲自验证,每年每人能获利1500元
- Sorting out XXL job learning
- MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
- Industry insight - how should brand e-commerce reshape growth under the new retail format?
- 解开C语言的秘密《关键字》(第六期)
- 中证500股指期货怎么开户,国内正规的股指期货平台有哪些,在哪里开户最安全?
- Three traversal methods of binary tree
- uni-app开发微信小程序动态渲染页面,动态改变页面组件模块顺序
猜你喜欢

Snipaste, the world's strongest screenshot software

esp32s3 IPERF例程测试 esp32s3吞吐量测试

一个有趣的网络掩码的实验

AI for Science:科研范式、开源平台和产业形态

Interview shock 60: what will cause MySQL index invalidation?

全志A13折腾备忘

带你认识图数据库性能和场景测试利器LDBC SNB
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)

剑指 Offer 04. 二维数组中的查找

ACL 2022 | TAMT proposed by Chinese Academy of Sciences: TAMT: search for a portable Bert subnet through downstream task independent mask training
随机推荐
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)
Three traversal methods of binary tree
Neo4j: basic introduction (I) installation and use
Minimum editing distance (linear DP writing method)
DM8:达梦数据库-锁超时
Hibernate operation Oracle database primary key auto increment
ssh工作流程及原理
nifi从入门到实战(保姆级教程)——身份认证
What is the next step in the recommendation system? Alispacetime aggregates GNN, and the effect is to sling lightgcn!
Detailed configuration of log4j
LeetCode_快速幂_递归_中等_50.Pow(x, n)
nmcli team bridge 基本配置
The world's fastest download tool XDM
Dynamic programming [III] (interval DP) stone merging
解除百度文库VIP、语雀、知乎付费限制,原来这么简单
An interesting experiment of netmask
Pycharm in Chinese
号称史上最难618,淘宝数据盘点你做对了吗?
How to find the movie and TV clips with the same lines? These 8 movies search for artifact, and find the corresponding segment in one line
Self taught ADT and OOP
