我正在为Libretro框架构建一个库,我想获得我的库的路径,这样我就可以在与我的library.so文件相同的目录中打开一个文件。
我按照How to implement readlink to find the path上的说明进行了操作,但这只给出了调用我的库的可执行文件的路径。
发布于 2019-01-30 23:39:28
在Linux上,使用Glibc扩展dladdr()。
#include <dlfcn.h>
std::string get_library_path() {
Dl_info dl_info;
if(0 != dladdr((void*)get_library_path, &dl_info))
return std::string(dl_info.dli_fname);
else
return std::string();
}在Windows上,等效项是GetModuleFileName()
https://stackoverflow.com/questions/54444064
复制相似问题