mcberk / wrapitk

Automatically exported from code.google.com/p/wrapitk
0 stars 0 forks source link

Java modules must be loaded with RTLD_GLOBAL|RTLD_NOW on linux #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Otherwise, objects can't be casted between some modules.
JavaMedianImageFilter fails for this reason.

This is likely to be true for the other languages as well. Python already
has it, and tcl seems to have it too. We'll have to take care about that
for other new languages.

The load with the right flags was achieved by the CWD and itkbase classes
in wrapitk stable.

#if !defined(_WIN32)
# include <dlfcn.h>

int JavaCWD::Load(const char* lib)
{
  return dlopen(lib, RTLD_GLOBAL|RTLD_NOW)? 1:0;
}
#else
int JavaCWD::Load(const char* lib)
{
  return 0;
}
#endif

  // Method called by wrapper code to load native libraries.
  public static void LoadLibrary(String name)
    {
    // Change to directory containing libraries so dependents are found.
    String old = JavaCWD.GetCWD();
    JavaCWD.SetCWD(libDir);
    String sep = System.getProperty("file.separator");
    String lib = System.mapLibraryName(name);
    String libPath = libDir + sep + lib;
    if( (new java.io.File(libPath)).exists() )
      {
      JavaCWD.Load(libPath);
      System.load(libPath);
      }
    else
      {
      // System.loadLibrary() create the lib name by itself, but not
JavaCWD.Load()
      // so one must get lib and the other name
      JavaCWD.Load(lib);
      System.loadLibrary(name);
      }
    JavaCWD.SetCWD(old);
    }

Original issue reported on code.google.com by gaetan.l...@gmail.com on 9 Feb 2009 at 1:00

GoogleCodeExporter commented 9 years ago

Original comment by gaetan.l...@gmail.com on 22 Feb 2009 at 10:34