linux shared library中获得自身和…

来源:互联网 发布:济南大学软件外包 编辑:程序博客网 时间:2024/06/04 19:14
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "dlfcn.h"
#include "mydll.h"

int SayHello()
{
    charbuf[1024];
    int rslt =readlink("/proc/self/exe", buf, 1024); //exe路径
   printf("executable file path: [%s]\r\n", buf);


    Dl_infodl_info;
   dladdr((void*)SayHello, &dl_info); //so文件路径
   printf("modules loaded path : [%s]\r\n", dl_info.dli_fname);
    return0;
}

以上是dll的函数,调用dll的demo需要链接libdl库



如果以main()作为入口函数,一个简单的方法是
#include <libgen.h>
chdir(dirname(argv[0]));
0 0
原创粉丝点击