📄 dy.c
字号:
/*dy.c :to use the lib of my.so under linux---date:041201*/#include <stdio.h>#include <dlfcn.h> //包含动态链接功能的接口文件#define SOFILE "./my.so" //指定动态链接库名字#define SHARED //定义宏,确认共享,以便引用动态函数#include "datetime.h"void main(void){ DATETYPE d; TIMETYPE t; void *dp; char *error; puts("example of lib"); printf("example of lib"); dp = dlopen(SOFILE,RTLD_LAZY); //RTLD_LAZY as a flag :finished in running the function of the lib //another flag is RTLD_NOW, means that all the undefined must be solved before the return of the "dlopen" if(dp == NULL) { fputs(dlerror(),stderr); exit(1); } getdate = dlsym(dp,"getdate");//定位取日期函数 error = dlerror();//监测错误 if(error) { fputs(error,stderr); exit(1); } getdate(&d);//调用此共享函数 printf("current date:%04d-%02d-%02d\n",d.year,d.mon,d.day); gettime=dlsym(dp,"gettime");//定位取时间函数 error = dlerror(); if(error) { fputs(error,stderr); exit(1); } gettime(&t);//调用此共享函数 printf("current time:%02d:%02d:%02d\n",t.hour,t.min,t.sec); dlclose(dp); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -