dlopen을 통해 모듈 (공유 객체)을로드하려고 시도하면로드되지 않습니다.공유 객체를로드하기위한 dlopen 사용을위한 기본 경로
말, 내가 testshobj.c 다음 가지고 있습니다 : 이제
// testobj.c
int dummy() {
return 5;
}
을, 나는 컴파일라는 이름의 공유 오브젝트와 링크 testobj.c testshobj.pm tjrough g ++ 컴파일러 : 이제
g++ testshobj.c -G -o testshobj.pm
모듈을로드 할 수 없습니다, 그것은 말한다
#include <iostream>
using namespace std;
#include <dlfcn.h>
int main(int argc, char **argv) {
const char *modname = "testshobj.pm";
void *handle = dlopen(modname,RTLD_LAZY);
if(!handle) {
cout << "can't load module: " << modname << ": " << dlerror() << endl;
return(1);
}
return 0;
}
:하지만, 나는 다음과 같이 testdlopen.c이 testshobj.pm : ld.so.1을 : 테스트를 dlopen : 치명적인 : testshobj.pm : open failed : 파일이나 디렉토리가 없습니다.
My Q : dlopen 호출의 기본 경로는 무엇입니까? 내가
const char *modname = "testshobj.pm";
의
const char *modname = "./testshobj.pm";
대신 사용하는 경우 아무 문제가 없습니다. 기본값 인 ./을 생략하면 어떨까요?
읽기 *주의 * 당신의 문서 [dlopen을 (3)] (http://man7.org/linux/man-pages/man3/dlopen. 3.html). 'LD_LIBRARY_PATH'가 이미 중요한 경로로 설정되어있을 수 있으므로 파일 경로에'/' –