Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Can't find dependent libraries of native module (DLL)
Can't find dependent libraries of native module (DLL) [message #61708] Wed, 15 February 2006 20:53 Go to next message
Nathan Beyer (Cerner) is currently offline Nathan Beyer (Cerner)Friend
Messages: 6
Registered: July 2009
Junior Member
Setup: Sun JRE 5.0_6, Windows XP, Eclipse 3.1.2

I have a piece of native code that I'm loading from a bundle, but it's
unable to find the dependent libraries that are packaged next to them.
I've tried configuring all of the DLLs using the Bundle-NativeCode
manifest header, as well as just placing them in the "os/win32/x86" folder
within the bundle, but they both fail to load the dependent DLLs.

Here's an example of the plug-in's structure:

Plugin
* ModuleLoader - System.loadLibrary("module_java");
* /os/win32/x86/module_java.dll
* /os/win32/x86/module.dll

The Java code loads the "module_java.dll" fine, but the "module.dll" isn't
found and I get a popup that says "The application has failed to start
because MODULE.dll was not found. Re-installing the application may fix
this problem." Within the VM an error is thrown:
"java.lang.UnsatisfiedLinkError:
C:\dev\ws\default_3_1\pluginA\os\win32\x86\module_java.dll: Can't find
dependent libraries".

If I move the dependent DLLs into the PATH, everything works fine, but
this defeats the purpose of packaging the DLLs into the bundles. Any
thoughts or suggestions on getting these dependent DLLs in the path?

Thanks,
-Nathan
Re: Can't find dependent libraries of native module (DLL) [message #61733 is a reply to message #61708] Thu, 16 February 2006 00:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

Firstly, using os/ws/arch is a deprecated way of referring to DLLs. For OSGI stuff,they should be in the root (preferably provided by a fragment, so you can partition the OS stuff out into different fragments).

Secondly, the problem is that whilst Eclipse knows the search directory to look for these things, Windows doesn't. In this case (presumably) module_java.dll refers to module.dll so the resolution goes like:

Eclipse: Hey, Windows, can you have a look for module_java? I'm pretty sure I've seen it in os/win32/x86 somewhere.

Windows: No problem. Oh look, here it is (loads dll). Hang on a sec, it turns out that module_java.dll needs module.dll. I'll look for it in the only place I know; the PATH. Nope, not in /windows/system32, nope, not in /windows/dll/ ...

So the problem is that whilst Eclipse tells windows where to load the original DLL from, Windows isn't smart enough to look in exactly the same place for dependent libraries. (Putting '.' on the path doesn't help either, because '.' is the directory from where you launched Eclipse.exe).

However, all is not lost. You can give Windows a helping hand:

Eclipse: Hey, Windows. Can you load 'module.dll' for me? It's in os/win32/x86.

Windows: Sure, no problem.

Eclipse: Hey, Windows. Can you load 'module_java.dll' for me? It's in os/win32/x86.

Windows: Sure. Hang on, it turns out module_java.dll depends on module.dll. Fortunately, I've already loaded it before so I'll just use it.

In a nutshell;

System.loadLibrary("module");
System.loadLibaray("module_java");

and don't forget to get rid of the os/win32/x86 directory structure ...

Alex.
Re: Can't find dependent libraries of native module (DLL) [message #61757 is a reply to message #61733] Thu, 16 February 2006 02:28 Go to previous messageGo to next message
Nathan Beyer (Cerner) is currently offline Nathan Beyer (Cerner)Friend
Messages: 6
Registered: July 2009
Junior Member
Thanks, I'll give the dependency loading a try.

Do you know of any links/documents with some best practices around OSGi
bundling and native code?

I was planning on using the OSGi Bundle-NativeCode to declare the native
libraries, but if I put all the modules in the root of the bundle (or
fragment), then I don't have to us that manifest header? I looked at the
OSGi specs, but it didn't say anything about default paths, at least that
I could find.

Thanks.
Re: Can't find dependent libraries of native module (DLL) [message #61921 is a reply to message #61757] Thu, 16 February 2006 21:29 Go to previous messageGo to next message
Stepan Rutz is currently offline Stepan RutzFriend
Messages: 52
Registered: July 2009
Member
I am using the Bundle-NativeCode myself to use a dll/so and another one it
depends on. Conveniently one can specify multiple libs within the
native-code manifest entry. That solved the problem of getting ld.so (or
the equivalent runtime-linker on windows) to load native code which i have
in my plugin.

I do have my native libs in subdirectories and not the root-dir of a
plugin, so i guess for that to work the bundle-nativepath is mandatory.

Apparently the swt-win32 plugin doesn't need that manifest entry. I wonder
how that works out since the library is called swt-win32-3139.dll from
the win32 swt fragment.

public class OS extends Platform {
static {
Library.loadLibrary ("swt"); //$NON-NLS-1$
}

...

The code above loads just "swt" though. This is probably related to how
windows resolves and loads dlls and it is definately confusing to me.

Anyhow, OSGI copies those dlls to the configuration area and loads them
from there ... eg when i start eclipse i have the swt library copied to

eclipse\configuration\org.eclipse.osgi\bundles\4\1\.cp\swt-w in32-3139.dll

and loaded from there. Looks like the runtime-linker knows that path as
one of the paths to search for libs (afaik PATH on windows and
LD_LIBRARY_PATH on linux).

Hope this helps you a bit at least, i am myself more confused than 5
minutes ago

Stepan
Re: Can't find dependent libraries of native module (DLL) [message #61944 is a reply to message #61921] Thu, 16 February 2006 21:37 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

There's an EclipseBundleLoader and an OSGIBundleLoader class. The former delegates to the latter initially, and the OSGIBundleLoader class looks for DLLs in the root of the plugin. The EclipseBundleLoader uses the older Eclipse-style mecahnism of ${ws}${os}${arch} if it can't be found in the OSGIBundleLoader's lookup.

Although the SWT library is loaded via System.loadLibrary(), I seem to recall that there's a custom classloader kicking around in there that does the resolution. It's a bit vague, but I seem to recall that there's a method like 'resolveLibrary(String name)' that does 'return name + "-" + os + "-3139".

If I ever come across it again, I'll post it here :-)

Alex.
Previous Topic:J2ME Foundation on "full" Windows
Next Topic:Exporting a package from a jar library in a plugin's classpath.
Goto Forum:
  


Current Time: Thu Apr 25 20:25:59 GMT 2024

Powered by FUDForum. Page generated in 0.03074 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top