0

While trying to load a module (shared object) through dlopen, it fails to load.

Say, I have testshobj.c having the following:

// testobj.c

int  dummy() {
  return  5;
}

Now, I compile and link testobj.c as shared object named testshobj.pm tjrough g++ compiler:

g++ testshobj.c -G -o testshobj.pm

Now, I have testdlopen.c as below:

#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;
}

But, it says, can't load module: testshobj.pm: ld.so.1: testdlopen: fatal: testshobj.pm: open failed: No such file or directory

My Q: What is the default path in dlopen call? If I use

const char *modname = "./testshobj.pm";

instead of

const char *modname = "testshobj.pm";

There is no problem. What about the default, i.e. if I omit ./?

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • Read *carefully* your documentation of [dlopen(3)](http://man7.org/linux/man-pages/man3/dlopen.3.html). I believe that your program should add the `./` if the filepath don't contain any `/` – Basile Starynkevitch Sep 16 '14 at 11:29

1 Answers1

0

I have got answer to my above query, posting the answer for every one else's help. LD_LIBRARY_PATH should be defined as . (current directory) (if not already set) as:

 export LD_LIBRARY_PATH=.
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69