linux shared library中获得自身和…

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "dlfcn.h"
#include "mydll.h"

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


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

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



如果以main()作为入口函数,一个简单的方法是
#include
chdir(dirname(argv[0]));

你可能感兴趣的:(linux)