Frage

getcwd( buff, 1024); 

says current following working path; what should I do?

buff = "/home/online0227/my project/Tutorial/Tutorial 1 Device Seletion\0"

I am trying to load my .so file using following function on Linux but they all fail. What is correct path to describe the path to my .so file?

   m_hSO = ::dlopen("..//..//..//..//..//so//myso.so", RTLD_LAZY);
   if(!m_hSO) {
   m_hSO = ::dlopen("..//..//..//..//..//so/myso.so", RTLD_LAZY);
   }
   if(!m_hSO) {
   m_hSO = ::dlopen("../../../../../so/myso.so", RTLD_LAZY);
   }
   if(!m_hSO) {
   m_hSO = ::dlopen("..//..//so/myso.so", RTLD_LAZY);
   }
War es hilfreich?

Lösung

  1. Consider using the path separator "/" and not "//". I don't believe that any bad effects will come from using "//" but "/" should suffice.

  2. Set LD_LIBRARY_PATH and have that include the location of your shared library. This is the best way to make sure that dlopen() (or ::dlopen()) find your library. Remember that 'relative paths' are relative to the current working directory and that really depends on the current working directory when the program is launched and any changes to current working directory by any code up to the point when ::dlopen() is called.

  3. As to why your program is failing to find the .so when you call ::dlopen() you should call getcwd() and find out what it says. That will help you adjust the relative path. But, let me reiterate that this is a bad practice unless you have some very good reason to do so.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top