当前位置:网站首页>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
边栏推荐
- LeetCode_ Fast power_ Recursion_ Medium_ 50.Pow(x, n)
- 秒云荣获《2022爱分析 · IT运维厂商全景报告》智能运维AIOps市场代表厂商
- Configuration of thymeleaf
- Neo4j:入门基础(一)之安装与使用
- [high frequency interview questions] difficulty 1.5/5, LCS template questions
- Uniapp drop-down layer selection box effect demo (sorting)
- uni-app 使用escook/request-miniprogram插件发请求说明
- Unzip log. GZ file
- 【粉丝福利】今天给大家介绍一个白捡钱的方法-可转债,本人亲自验证,每年每人能获利1500元
- nmcli team bridge 基本配置
猜你喜欢
随机推荐
Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
中证500股指期货怎么开户,国内正规的股指期货平台有哪些,在哪里开户最安全?
剑指 Offer 04. 二维数组中的查找
对象序列化
关于枚举类的两种用法
Dm8: Dameng database - lock timeout
Interview shock 60: what will cause MySQL index invalidation?
Operators are also important if you want to learn the C language well
log4j的详情配置
mybaitis生成器详解
栈的计算(入栈出栈顺序是否合法)-代码
今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
【医学分割】unet3+
Nmcli team bridge basic configuration
AI for Science:科研范式、开源平台和产业形态
mysql学习1:安装mysql
build.gradle 配置
Utilisation de la file d'attente des messages
Talk about go language and cloud native technology
Unzip log. GZ file









![Dynamic programming [III] (interval DP) stone merging](/img/a4/82c4d63b8df5d092a96b80dd497147.jpg)
