0

I have created a DLL by Visual Studio and wrote a JNI interface to use that DLL from Java app. I have successfully run DLL from my PC. But when I run Java app from another machine, I got this error: java.lang.UnsatisfiedLinkError: C:\Users\user.jss\windows\project.dll: Can't find dependent libraries. The problem solved when I install Visual Studio on other PC. Is there any setting in Visual Studio to remove this dependency when creating DLL?

Appreciate your help.

michael
  • 13
  • 1

1 Answers1

1

What is project.dll? Is this the name of the JNI DLL? You must ship your platform dependent native libraries (and all of their run-time dependencies) with your Java application. If it is failing because project.dll requires the MSVC runtime, then you can either ship the runtime with the application or avoid it with a different toolchain like MinGW.

Alex Barker
  • 4,316
  • 4
  • 28
  • 47
  • project.dll is used by JAR file through JNI. Do you mean MSVC related dlls by runtime? Porting to MinGW will not be so easy because I use winscard library that is inside windows SDK. – michael Aug 30 '19 at 00:42
  • That explains why you need extra runtime dlls. The easiest answer would be to have your installer check for the appropriate MSVC runtime and install it if it doesn't exist. Alternatively you could try and statically link the runtime dependencies at the cost of the project.dll file size. – Alex Barker Aug 30 '19 at 02:51
  • Thanks for your explanation.If your second solution will solve my problem it ll be better. Is there a way to link statically against vc runtime? I searched and read this post, similar to my problem. https://stackoverflow.com/questions/1279292/how-do-i-create-a-win32-dll-without-a-dependency-on-the-c-runtime. But when I use /NODEFAULTLIB linker option I get thousands of unresolved external errors. – michael Aug 30 '19 at 16:14
  • I am not sure on the support for static linking in the MSVC world. I know there are some MSDN how-to's but I am not sure if they are suitable for your use case. – Alex Barker Aug 30 '19 at 16:18
  • 1
    Thank you very much Alex. I have statically linked runtime. In **Configuration Properties->C/C++->Code Generation->Runtime Library**. I changed to Multi-threaded (/MT) option for Release mode which was Multithreaded DLL. I am able to run Java app from other machines without VC runtime. – michael Aug 31 '19 at 14:07