Skip to content

lurenyang418/c-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

静态库与动态库的简单使用案例

生成动态库

gcc -fPIC -shared -o lib/libhello.so hello.c

# 等价于如下两句
gcc -fPIC -c hello.c
# 生成 hello.o
gcc -shared -o libhello.so hello.o

测试

# 编译
gcc -o main main.c -I./include -L./lib -lhello
# 临时设置动态链接库
export LD_LIBRARY_PATH=lib
# 运行
./main

生成静态库

gcc -c hello.c # hello.o
# 静态打包
ar -rcs lib/libhello.a hello.o # libhello.a

测试

gcc -o main main.c -Iinclude -Llib -lhello
# 运行
./main

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages