title: C++ linux: dlopen can't find .so library
body: <p>Reworded Question (although it's been solved already):</p>
  
  <p>I've been having trouble using dlopen(3) to load a shared object library on linux.  The library is part of a system of libraries built by me that are all loaded at runtime by a central executable.  All of this is organized into a single workspace in Code::Blocks, where each project is given its own folder within a directory called Source, which is to be shipped with the program.  The build directory of the executable is two directories backward from its own source code so that the exectuable and the Source folder are in the same directory,  The libraries also build to the same directory as the executable, so naturally I pass the name of the library I'm trying to open as shown:</p>
  
  <pre><code>int main(int argc, char** argv) {
      void* hLibrary = dlopen("libLibrary.so", RTLD_NOW | RTLD_GLOBAL);
      if(hLibrary == NULL) {
          fprintf(stderr, "%s\n", dlerror());
          return 1;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This was working at one point when the build directory was the same as the source code, until I changed the directories of the source code around to the arrangement described above.  The problem at this point is that dlerror() returns "Cannot open libLibrary.so: no such file or directory," even though the file clearly exists and is in the same directory as the executable.  I then tried passing in "/libLibrary.so" instead, because according to the man page on dlopen(3), adding a / indicates a relative directory.  This returned the same error.</p>
  
  <p>The solution to this was that a "./" was needed - where "." represents the working directory of the executable - and the working directory needed to be changed in Code::Blocks to where the executable was to be built.  The following works perfectly:</p>
  
  <pre><code>void* hLibrary = dlopen("./libLibrary.so", RTLD_NOW | RTLD_GLOBAL);
  </code></pre>
  
  <p>This doesn't really show the full solution, but the following is basically the equivalent of what I'm doing:</p>
  
  <pre><code>void* hLibrary = dlopen("./../../libLibrary.so", RTLD_NOW | RTLD_GLOBAL);
  </code></pre>
  
  <p>Hopefully this explains the situation a little better.</p>