• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10625
  • Last Modified:

DLL can't find dependent libraries

I'm writing an application that uses native code (which I didn't write) which is bundled in several DLLs.  I put them into a folder \lib.

At first when I ran the app, it complained that it could not find main.dll (which is the DLL that depends on all others).  So then, I tried setting -Djava.library.path and it found main.dll, but still gave me an error "can't find dependent libraries".

I read from http://dev.eclipse.org/newslists/news.eclipse.technology.equinox/msg01581.html that this is caused because Windows looks in PATH for the DLLs the second time around.  So I put the \lib folder into PATH environment variable, which made it work.

However, I would prefer not having to set environment variables.

Some more background info... I was actually able to use the same native code DLLs in a simpler project that just had all the source code and classes in the project root directory, which had all the DLLs too.  I could do this without setting java.library.path or PATH.  So I feel that it should be possible to do the same for the more complex project too.

One thing that puzzles me is why for the simple project, I didn't have to do anything (beside setting the classpath) and Windows was able to find the other DLLs that main.dll depends on but in the more complex project, Windows couldn't find them.

Any direction or hints would be greatly appreciated. Thanks!
0
alskdj80
Asked:
alskdj80
  • 7
  • 4
  • 2
  • +1
1 Solution
 
CEHJCommented:
Copy all dlls to %WINDIR%
0
 
alskdj80Author Commented:
Isn't there any way to not set anything OS-specific?  I need to run this Java app on Linux too and would prefer not to deal with code like "if (Windows) copy dlls to %WINDIR%, else if (Linux) do something else"

Is there some way of specifying the library path for the Java app or something?
0
 
maheshexpCommented:
add the path of your DLL into the system path before executing your java code.

String newLib = "C:/Your Path";

String system_path = System.getProperty("java.library.path");
String path_seperator = System.getProperty( "path.separator" ); // ":" for unix, ";" for windows

System.setProperty("java.library.path", newLib + path_seperator +  system_path );
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
>>Isn't there any way to not set anything OS-specific?

DLLs are already OS-specific. They won't run on Linux. You'll need to compile a shared library (.so) for that
0
 
alskdj80Author Commented:
maheshexp,
Setting the java.library.path will not work because Windows only uses it main.dll but then goes back to using PATH for the dependent dlls.  Therefore, I get a "can't find dependent libraries" error.

CEHJ,
Yes, you're right, but I was just planning on dumping the .dll and .so files in /lib.  As long as Java can find the libraries, then it doesn't matter what OS I'm using.
0
 
CEHJCommented:
>>but I was just planning on dumping the .dll and .so files in /lib.

But /lib doesn't exist on Windows. The nearest thing would be what i suggested or %SYSTEMROOT%
0
 
alskdj80Author Commented:
Oh, no, I meant myapp\lib.  Basically, I want the .dlls and .so files to be contained in the application directory.

Do you know how Windows checks for library files?  Because I know that when my app didn't have packages and everything was lumped into myapp\, it worked.  But myapp\ isn't in the Windows PATH variable so I'm a little confused as to why it worked in that scenario.
0
 
CEHJCommented:
It's not the PATH variable that's important, but the Java property java.library.path

There is some overlap between the two. Check out the Java property
0
 
maheshexpCommented:
>>Setting the java.library.path will not work because Windows only uses it main.dll but then goes back to

The all the required library files are always detected in the path stored in the property "java.library.path".
It's not that for few DLLs it will take the java.library.path and for others it takes another path :-)
0
 
CEHJCommented:
alskdj80 - i don't understand what you mean by 'unsuitable'. Native libraries are by definition platform-specific and need to be treated per platform. It's as simple as that
0
 
alskdj80Author Commented:
Oh, no, sorry, I didn't mean unsuitable.  I just meant that I didn't get an answer that I was hoping for.

The thing is that I was able to make work if I dumped it all the dll and so files (both platforms) into the myapp/ root directory so that isn't platform-specific.  Because of this, I was hoping for a platform-unspecific solution for my situation, which had packages. Perhaps this was impossible.

Please don't misunderstand!  I really do appreciate everything that you did to help and that's why I wrote to give you a portion of the points, but to give the full amount of points for a problem that I still have seems expensive, especially since this is my last 500 points, :(
0
 
CEHJCommented:
FYI package/no packages is irrelevant. I'm happy to abide by your suggestion
0
 
LunchyCommented:
Points reduced 500 to 150 for award.

Lunchy
Friendly Neighbourhood Community Support Moderator
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now