有时候发布的lib,还需要相关的资源,所需要定位到自己加载的路径。
#include <dlfcn.h>
static void empty_dladdr(){
}
Dl_info dl_info;
dladdr((void *)empty_dladdr,&dl_info);
std::string libPathAndName=(std::string)dl_info.dli_fname;
std::size_t post=libPathAndName.find_last_of("/")+1;
std::string libPath=libPathAndName.substr(0,post);