当前位置:网站首页>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
边栏推荐
- MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
- TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
- Sorting out XXL job learning
- Interview shock 60: what will cause MySQL index invalidation?
- script defer async模式
- 【医学分割】unet3+
- Thymeleaf的相关知识
- Stack calculation (whether the order of entering and leaving the stack is legal) - Code
- JMeter connection DM8
- picocli-入门
猜你喜欢
随机推荐
[on Nacos] get started quickly
How to close windows defender Security Center
Topic37——64. 最小路径和
Browser cookie to selenium cookie login
LeetCode_ Fast power_ Recursion_ Medium_ 50.Pow(x, n)
Dm8: Dameng database - lock timeout
printf不定长参数原理
word文本框换页
ViewPager2使用记录
全志A13折腾备忘
Esp32s3 iperf routine test esp32s3 throughput test
What's the matter with Amazon's evaluation dropping and failing to stay? How to deal with it?
关于枚举类的两种用法
ACL 2022 | TAMT proposed by Chinese Academy of Sciences: TAMT: search for a portable Bert subnet through downstream task independent mask training
Unzip log. GZ file
Hibernate operation Oracle database primary key auto increment
Topic38——56. Consolidation interval
MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
Time management understood after being urged to work at home










