当前位置:网站首页>Dynamic link library nesting example
Dynamic link library nesting example
2022-06-13 06:19: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);
}
function j result :
[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
- When the dynamic library is made , It can also be combined with other dynamic libraries .
- -I( Notice that it's capital i) to gcc Add the path of the customized header file ,
-Imyinclude. - -L to gcc Add additional search library paths .
- -l ( A lowercase letter L) Parameters are used to specify the library that the program will link to ,-l The parameter is followed by the library name , Math library file name is libm.so, It's easy to see , Put the header of the library file name lib And tail .so It's the name of the library ,
lm.
边栏推荐
- Time complexity and space complexity
- Free screen recording software captura download and installation
- Introduction to USB learning (I) -- Dongfeng night flower tree
- Adding classes dynamically in uni app
- El form form verification
- Solution: vscode open file will always overwrite the last opened label
- The boys x pubgmobile linkage is coming! Check out the latest game posters
- Echart柱状图:堆叠柱状图显示value
- Detailed explanation of Yanghui triangle
- 微信小程序:基础复习
猜你喜欢

Echart line chart: different colors are displayed when the names of multiple line charts are the same

Wechat applet (get location)

Wechat applet: click the event to obtain the current device information (basic)

1+1>2,Share Creators可以帮助您实现

超有范的 logo 在线设计制作工具

Binary search

楊輝三角形詳解

推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
![[DP 01 backpack]](/img/be/1e5295684ead652eebfb72ab0be47a.jpg)
[DP 01 backpack]

After clicking the uniapp e-commerce H5 embedded applet, the page prompts "the page iframe does not support referencing non business domain names"
随机推荐
Wechat applet (function transfer parameters, transfer multiple parameters, page Jump)
Echart柱状图:x轴显示value,y轴显示类别
Regular verification of mobile phone number, landline email ID card
RN Metro packaging process and sentry code monitoring
Cmake add -fpic option GCC
欧姆龙平替国产大货—JY-V640半导体晶元盒读写器
Echart histogram: stack histogram value formatted display
Time conversion'2015-04-20t11:12:00.000+0000 '
Echart柱状图:堆叠柱状图value格式化显示
JS convert text to language for playback
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
Security baseline check script - the road to dream
【新手上路常见问答】关于技术管理
电镀挂具RFID工序管理解决方案
万能播放器 PotPlayer 的下载与安装,直播流 m3u8 导入
347. top k high frequency elements heap sort + bucket sort +map
Uni app provincial and urban linkage
Wechat applet (pull-down refresh data) novice to
[var const let differences]
Introduction to USB learning (I) -- Dongfeng night flower tree