当前位置:网站首页>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
边栏推荐
- Nmcli team bridge basic configuration
- Convn-n dimensional convolution
- PyCharm汉化
- 行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
- Sword finger offer 04 Find in 2D array
- How to participate in openharmony code contribution
- 【医学分割】unet3+
- Dm8: Dameng database - lock timeout
- An interesting experiment of netmask
- Talk about go language and cloud native technology
猜你喜欢

Secyun won the "2022 AI analysis · it operation and maintenance vendor panorama report" as the representative vendor of intelligent operation and maintenance aiops Market

Quanzhi A13 tossing memo

全球最快下载工具 XDM

nmcli team bridge 基本配置
![Dynamic programming [III] (interval DP) stone merging](/img/a4/82c4d63b8df5d092a96b80dd497147.jpg)
Dynamic programming [III] (interval DP) stone merging

【粉丝福利】今天给大家介绍一个白捡钱的方法-可转债,本人亲自验证,每年每人能获利1500元

Uniapp drop-down layer selection box effect demo (sorting)

全志A13折腾备忘

Private dry goods sharing: how to implement platform in Enterprise Architecture

剑指 Offer 04. 二维数组中的查找
随机推荐
Utilisation de la file d'attente des messages
Mathematical knowledge -- ideas and examples of game theory (bash game, Nim game, wizov game)
yml的配置
【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(三)
Pycharm in Chinese
Sword finger offer 04 Find in 2D array
Getting started with go web programming: validators
convn-N 维卷积
Private dry goods sharing: how to implement platform in Enterprise Architecture
Interview shock 60: what will cause MySQL index invalidation?
浅谈软件研发的复杂性与效能提升之道
本地可视化工具连接阿里云centOS服务器的redis
Centos7命令行安装Oracle11g
Local visualization tool connects to redis of Alibaba cloud CentOS server
浏览器输入url地址,到页面渲染发生了什么
Two usages of enumeration classes
Topic38——56. 合并区间
Ssh server configuration file sshd_ Config and operation
数据库系列:MySQL索引优化与性能提升总结(综合版)
Picocli getting started
