This discussion is archived
8 Replies Latest reply: Jun 7, 2011 4:55 PM by jschellSomeoneStoleMyAlias RSS

How to resolve dll dependency with external library.

846238 Newbie
Currently Being Moderated
Hi all,

My native code use "sqlite3.lib" and perform certain data operations. I have generated the dll for the same using Visual studio appropriately.

I'm able to build the dll file properly. But, when used along with my java project (A bundle), I get the following error:

Bundle Exception: Bundle Start failed
java.lang.UnsatisfiedLinkError: D:\Knopflerfish_3.0\K_3.0\osgi\fwdir\bs\27\jar0\DbNativeInterface.dll: Can't find dependent libraries

I'm using knopflerfish OSGi framework. I'm also very sure the java is able to locate my dll file, but further it is not able to resolve the dependecy of this dll with sqlite3.lib.

Please guide me with solutions if any.

Thanks in advance.
Vinay
  • 1. Re: How to resolve dll dependency with external library.
    EJP Guru
    Currently Being Moderated
    Does sqlite3.lib correspond to sqlite3.dll? and if so have you deployed that DLL with your own?
  • 2. Re: How to resolve dll dependency with external library.
    846238 Newbie
    Currently Being Moderated
    Hi,

    Yes, sqlite3.lib corresponds to sqlite3.dll. (I'm not building this dll. It is used as available as part of SQLite package. I'm only referencing sqlite3.lib in Visual studio to build DbNativeIntreface.dll)

    I had packaged both the dll's (DbNativeInterface and sqlite3) in the bundle jar, and I tried calling System.loadLibrary for sqlite3.dll before actually loading my custom Dll (DbNativeInterface).

    sqlite3.dll however loads successfully, but same error persist while loading my custom dll file. (Unable to resolve dependency of my dll with sqlite3)

    Please let me know if it is the right way to deploy the DLL on my own ??

    Thank you very much,
    Vinay.

    Edited by: 843235 on Jun 2, 2011 1:14 AM
  • 3. Re: How to resolve dll dependency with external library.
    EJP Guru
    Currently Being Moderated
    Are both the DLLs in the same place at execution time?

    You don't have to load the sqlite3 DLL yourself, only your JNI DLLs.
  • 4. Re: How to resolve dll dependency with external library.
    846238 Newbie
    Currently Being Moderated
    Hi,

    Yes, I packaged both Dll's as part of bundle jar. So while loading the bundle into knopflerfish framework, both of these were in the same location.

    I have even tried with out loading the sqlite3 manually. Issue was the same.

    Vinay.
  • 5. Re: How to resolve dll dependency with external library.
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    843235 wrote:
    Hi,

    Yes, I packaged both Dll's as part of bundle jar. So while loading the bundle into knopflerfish framework, both of these were in the same location.
    Does the above mean that the dlls are extracted from the jar and placed in the file system? Have you actually verified that by inspection?

    You can use System.getenv() to determine what the shared library path is for the VM when it is running. Specifically the PATH variable.
  • 6. Re: How to resolve dll dependency with external library.
    handat Expert
    Currently Being Moderated
    You can use a dependency checker on the DLL to find out what other DLL files it loads and make sure those DLL files exist and are in the system path. See the following link for a useful dependency checker tool: http://www.dependencywalker.com/
  • 7. Re: How to resolve dll dependency with external library.
    846238 Newbie
    Currently Being Moderated
    Hi,

    Thank you all for your suggestion. My Issue is now resolved. But before I can tell about what I did, some response to your questions.

    The Dll's are extracted/moved from its location, and placed inside the bundle jar. This bundle jar is further located and installed in the Knopflerfish framework. The java.library.path was set to current directory. So it was able to locate and load my JNI dll file. But unable to link this dll with sqlite3.dll.

    SOLUTION: I copied sqlite3.dll to windows -> system32 folder. Things worked.

    Thank you again, since dll dependency check helped me avoid certain unnecessary dll dependency that was encountered by building the dll using Visual studio. I now build the dll using command line interface manually.

    Now, that things are working fine on Windows, I have been facing similar problem in Linux environment. Please look into my other thread
    "JNI : Linux java.lang.UnsatisfiedLinkError"

    I would prefer posting a new thread to avoid confusions. This thread related to windows is resolved.

    Thank you all.
    Vinay
  • 8. Re: How to resolve dll dependency with external library.
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    843235 wrote:
    SOLUTION: I copied sqlite3.dll to windows -> system32 folder. Things worked.
    That however is the wrong solution.

    It works because the library is now in the shared library path.
    It would also work if if was in some other location which was also on the shared library path. Such as if it was in the install directory and the shared library path, for the application, was set to point to that.

    Note as well, that per my question, bundling it into the jar does not server any purpose. The OS will not load it from the jar. It must be outside the jar.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points