当前位置:网站首页>动态链接库嵌套样例
动态链接库嵌套样例
2022-06-13 06:11:00 【Jia ming】
foo2.c
int foo2 = 20;
void foo2_func() {
}
foo1.c
extern int foo2;
int foo1 = 10;
int dummy = 20;
void foo1_func()
{
int a = foo2;
int b = dummy;
int c = foo1;
foo2_func();
}
main.c
#include <stdlib.h>
extern int foo1;
extern int foo1;
int a[2048];
int dummy = 10;
void main()
{
char *m = malloc(1024);
foo1 = 5;
foo1_func();
while(1)sleep(1000);
}
运行j结果:
[email protected]:~/Documents/test/libso$ gcc -shared -fPIC -o libf2.so foo2.c
[email protected]:~/Documents/test/libso$ gcc -shared -fPIC -o libf1.so foo1.c -L. -lf2
foo1.c: In function ‘foo1_func’:
foo1.c:11:5: warning: implicit declaration of function ‘foo2_func’; did you mean ‘foo1_func’? [-Wimplicit-function-declaration]
foo2_func();
^~~~~~~~~
foo1_func
[email protected]:~/Documents/test/libso$ gcc -o hello main.c -L. -lf1
main.c: In function ‘main’:
main.c:12:5: warning: implicit declaration of function ‘foo1_func’ [-Wimplicit-function-declaration]
foo1_func();
^~~~~~~~~
main.c:13:13: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration]
while(1)sleep(1000);
^~~~~
/usr/bin/ld: warning: libf2.so, needed by ./libf1.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: ./libf1.so: undefined reference to `foo2' /usr/bin/ld: ./libf1.so: undefined reference to `foo2_func'
collect2: error: ld returned 1 exit status
[email protected]:~/Documents/test/libso$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
[email protected]:~/Documents/test/libso$ gcc -o hello main.c -L. -lf1
main.c: In function ‘main’:
main.c:12:5: warning: implicit declaration of function ‘foo1_func’ [-Wimplicit-function-declaration]
foo1_func();
^~~~~~~~~
main.c:13:13: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration]
while(1)sleep(1000);
^~~~~
[email protected]:~/Documents/test/libso$ ./hello
^C
- 动态库在制作的时候,亦可结合其它动态库。
- -I(注意是大写的i)给gcc添加自定义的头文件的路径,
-Imyinclude。 - -L 给gcc添加额外的搜索库的路径。
- -l (小写L)参数就是用来指定程序要链接的库,-l参数紧接着就是库名,数学库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so去掉就是库名了,
lm。
边栏推荐
- USB debugging assistant
- Not in the following list of legal domain names, wechat applet solution
- 【美团笔试题】
- Sqlplus connection failure
- [spark]spark introductory practical series_ 8_ Spark_ Mllib (lower)__ Machine learning library sparkmllib practice
- Applet pull-up loading data
- Leetcode- detect uppercase letters - simple
- Echart histogram: stacked histogram displays value
- php 分布式事务 原理详解
- Huawei developer certification and deveco studio compiler Download
猜你喜欢

二分查找

智能数字资产管理助力企业决胜后疫情时代

Detailed explanation of PHP distributed transaction principle

USB debugging assistant (20191028)

自定义View —— 可伸展的CollapsExpendView

Detailed explanation of Yanghui triangle

AI实现亲人“复活”|老照片修复|老照片上色,免费APP推荐

Pod libwebp error reporting solution
![[compilation and assembly link] coff file and structure description](/img/73/fca3752327c31877ea8f56f96c009e.jpg)
[compilation and assembly link] coff file and structure description

Fichier local second Search Tool everything
随机推荐
【DP之01背包】
Local file search tool everything
[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib
Uniapp secondary encapsulates uview components, and the parent component controls display and hiding
Time complexity and space complexity
Applet export (use) public function, public data
Lamda expression
Leetcode planting flowers - simple
How to view APK version number from apk
Wechat applet jumps to H5 page with parameters
Using async await in applets
Turn to 2005
php redis 制作高迸发秒杀
Detailed explanation of PHP distributed transaction principle
杨辉三角形详解
Time conversion'2015-04-20t11:12:00.000+0000 '
The Boys x PUBGMOBILE 联动火热来袭!来看最新游戏海报
1+1>2,Share Creators可以帮助您实现
Introduction to USB learning (I) -- Dongfeng night flower tree
FusionPBX 安装 —— 筑梦之路