JavaCpp时出现UnsatisfiedLinkExcepti

JavaCpp时出现UnsatisfiedLinkExcepti

本文介绍了运行JavaCpp时出现UnsatisfiedLinkException示例(LegacyLibrary)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Visual构建和运行JavaCpp的 Studio 2008在Windows XP Professional(x86)上使用JDK 1.7.0和JavaCpp 0.3(bin),我得到以下输出。错误是在最后一个命令, java -cp javacpp.jar LegacyLibrary

I'm trying to build and run the LegacyLibrary Example of JavaCpp with Visual Studio 2008 on Windows XP Professional (x86) using JDK 1.7.0 and JavaCpp 0.3 (bin), and I get the following output. The error is on the last command, java -cp javacpp.jar LegacyLibrary.

C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp>dir
 Volume in drive C has no label.
 Volume Serial Number is 9099-0685

 Directory of C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hell
o_JNI\src\graf\JavaCpp

22/01/2013  10:19 AM    <DIR>          .
22/01/2013  10:19 AM    <DIR>          ..
04/11/2012  09:00 PM           109,991 javacpp.jar
22/01/2013  10:18 AM               297 LegacyLibrary.h
22/01/2013  10:19 AM             1,058 LegacyLibrary.java
               3 File(s)        111,346 bytes
               2 Dir(s)  362,833,334,272 bytes free

C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp>javac -cp javacpp.jar LegacyLibrary.java

C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp>java -jar javacpp.jar LegacyLibrary
Generating source file: C:\Documents and Settings\Brian\My Documents\Projects\Co
py of Hello_JNI\src\graf\JavaCpp\jniLegacyLibrary.cpp
Building library file: C:\Documents and Settings\Brian\My Documents\Projects\Cop
y of Hello_JNI\src\graf\JavaCpp\windows-x86\jniLegacyLibrary.dll
cl /IC:\jdk1.7.0\include /IC:\jdk1.7.0\include\win32 "C:\Documents and Settings\
Brian\My Documents\Projects\Copy of Hello_JNI\src\graf\JavaCpp\jniLegacyLibrary.
cpp" /W3 /Oi /O2 /EHsc /Gy /GL /MD /LD /link "/OUT:C:\Documents and Settings\Bri
an\My Documents\Projects\Copy of Hello_JNI\src\graf\JavaCpp\windows-x86\jniLegac
yLibrary.dll" /LIBPATH:C:\jdk1.7.0\lib /LIBPATH:C:\jdk1.7.0\jre\bin\server jvm.l
ib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

jniLegacyLibrary.cpp
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(113) : warning C4996: 'strcpy': This function or v
ariable may be unsafe. Consider using strcpy_s instead. To disable deprecation,
use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(74) : s
ee declaration of 'strcpy'
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(115) : warning C4996: 'strncpy': This function or
variable may be unsafe. Consider using strncpy_s instead. To disable deprecation
, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(157) :
see declaration of 'strncpy'
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(185) : warning C4996: 'strdup': The POSIX name for
 this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See
 online help for details.
        c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\string.h(207) :
see declaration of 'strdup'
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(340) : warning C4244: 'argument' : conversion from
 'jlong' to 'size_t', possible loss of data
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(354) : warning C4244: 'argument' : conversion from
 'jlong' to 'size_t', possible loss of data
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(370) : warning C4244: 'argument' : conversion from
 'jlong' to 'size_t', possible loss of data
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(385) : warning C4244: 'argument' : conversion from
 'jlong' to 'size_t', possible loss of data
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(393) : warning C4244: 'argument' : conversion from
 'jlong' to 'size_t', possible loss of data
C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp\jniLegacyLibrary.cpp(956) : warning C4800: 'jboolean' : forcing value t
o bool 'true' or 'false' (performance warning)
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:jniLegacyLibrary.dll
/ltcg
/dll
/implib:jniLegacyLibrary.lib
"/OUT:C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\sr
c\graf\JavaCpp\windows-x86\jniLegacyLibrary.dll"
/LIBPATH:C:\jdk1.7.0\lib
/LIBPATH:C:\jdk1.7.0\jre\bin\server
jvm.lib
jniLegacyLibrary.obj
   Creating library jniLegacyLibrary.lib and object jniLegacyLibrary.exp
Generating code
Finished generating code

C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp>java -cp javacpp.jar LegacyLibrary
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Documents and Sett
ings\Brian\Local Settings\Temp\javacpp92803190928456\jniLegacyLibrary.dll: Can't
 find dependent libraries
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
        at java.lang.Runtime.load0(Runtime.java:792)
        at java.lang.System.load(System.java:1059)
        at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:422)
        at com.googlecode.javacpp.Loader.load(Loader.java:372)
        at com.googlecode.javacpp.Loader.load(Loader.java:319)
        at LegacyLibrary$LegacyClass.<clinit>(LegacyLibrary.java:8)
        at LegacyLibrary.main(LegacyLibrary.java:22)

C:\Documents and Settings\Brian\My Documents\Projects\Copy of Hello_JNI\src\graf
\JavaCpp>


推荐答案

问题是Visual Studio 2005和VS 2008不会自动链接到VC ++的内部库。解决方案是使用可执行文件中的必需库捆绑清单,如,或简单地使用Visual Studio 2010或更高版本。我使用VS 2010,我可以验证该示例现在运行正常。如果您碰巧尝试捆绑清单,请评论其他人以确认它是一个有效的修复。

The problem was that Visual Studio 2005 and VS 2008 do not automatically link to internal libraries of VC++. The solution is to either bundle a manifest with the required libraries in the executable, as described here, or to simply use Visual Studio 2010 or newer. I used VS 2010 and I can verify that the example now runs as expected. If you happen to try bundling the manifest, please comment for others to confirm that it's a valid fix.

源:

这篇关于运行JavaCpp时出现UnsatisfiedLinkException示例(LegacyLibrary)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 07:31