Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为 Libretro 框架构建一个库,我想获取我的库的路径,以便我可以在与我的文件相同的目录中打开一个library.so文件。
library.so
我按照如何实现 readlink 中的说明来查找路径,但这只是给了我调用我的库的可执行文件的路径。
在 Linux 上,使用 Glibc 扩展dladdr()。
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()
GetModuleFileName()