JNI HellowWorld 不满意链接错误 找不到依赖库
JNI HellowWorld unsatisfiedlinkError Can't find dependent libraries
我尝试了来自以下位置的Hello world JNI:
http://home.pacifier.com/~mmead/jni/cs510ajp/
我做了Java类:
public class ACTICamWrapperJNI {
public native void displayMessage();
static
{
System.loadLibrary("HelloWorldImp");
}
}
并调用它:
public static void main(String args[]) {
//</editor-fold>
System.out.println(System.getProperty("java.library.path"));
ACTICamWrapperJNI test = new ACTICamWrapperJNI();
}
CPP 文件如下所示:
#include <stdio.h>
#include "HelloWorld.h" // this header file was generated by javah
JNIEXPORT void JNICALL Java_HelloWorld_displayMessage(JNIEnv *env, jobject obj)
{
printf("Hello World!n");
}
我已经切换到JDK x86并使用X86编译:
C:DevelopmenttestJNI>javac HelloWorld.java
C:DevelopmenttestJNI>javac HelloWorld.java
C:DevelopmenttestJNI>javah -jni HelloWorld
我使用了 QT 文件夹中MINGW32的 gcc(希望没问题)
C:DevelopmenttestJNI>gcc -shared -I "C:Program Files (x86)Javajdk1.7.0_40include" -I"C:Program Files (x86)Javajdk1.7.0_40includewin32" HelloWorld.cpp -o HelloWorldImp.dll
注意我必须添加共享,否则出现错误:
undefined reference to `WinMain@16'
C:DevelopmenttestJNI>"C:Program Files (x86)Javajdk1.7.0_40binjava.exe" Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloWorld.displayMessage()V
at HelloWorld.displayMessage(Native Method)
at Main.main(Main.java:9)
请注意,我已经确保我运行的是x32 jdk的java,并且也使用x32版本进行编译,因为我的系统上也有x64。
也在NetBean IDE上尝试并遇到问题:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:WindowsSystem32HelloWorldImp.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1872)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1087)
at au.com.ricor.ACTICamWrapperJNI.<clinit>(ACTICamWrapperJNI.java:15)
at au.com.ricor.CameraPanel.main(CameraPanel.java:58)
我使用的 gcc 版本也是:
C:DevelopmenttestJNI>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/qt/tools/mingw48_32/bin/../libexec/gcc/i686-w64-mingw32/4
.8.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.8.0/configure --host=i686-w64-mingw32 --buil
d=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/t
emp/x32-480-posix-dwarf-r2/mingw32 --enable-shared --enable-static --disable-mul
tilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-
threads=posix --enable-libgomp --enable-lto --enable-graphite --enable-checking=
release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --d
isable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog
-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-boots
trap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --d
isable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic
--with-host-libstdcxx='-static -lstdc++' --with-libiconv --with-system-zlib --wi
th-gmp=/temp/mingw-prereq/i686-w64-mingw32-static --with-mpfr=/temp/mingw-prereq
/i686-w64-mingw32-static --with-mpc=/temp/mingw-prereq/i686-w64-mingw32-static -
-with-isl=/temp/mingw-prereq/i686-w64-mingw32-static --with-cloog=/temp/mingw-pr
ereq/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='rev2,
Built by MinGW-builds project' --with-bugurl=http://sourceforge.net/projects/mi
ngwbuilds/ CFLAGS='-O2 -pipe -I/temp/x32-480-posix-dwarf-r2/libs/include -I/temp
/mingw-prereq/x32-zlib/include -I/temp/mingw-prereq/i686-w64-mingw32-static/incl
ude' CXXFLAGS='-O2 -pipe -I/temp/x32-480-posix-dwarf-r2/libs/include -I/temp/min
gw-prereq/x32-zlib/include -I/temp/mingw-prereq/i686-w64-mingw32-static/include'
CPPFLAGS= LDFLAGS='-pipe -L/temp/x32-480-posix-dwarf-r2/libs/lib -L/temp/mingw-
prereq/x32-zlib/lib -L/temp/mingw-prereq/i686-w64-mingw32-static/lib -L/temp/x32
-480-posix-dwarf-r2/mingw32/opt/lib'
Thread model: posix
gcc version 4.8.0 (rev2, Built by MinGW-builds project)
谢谢
威廉
要么将类从 au.com.ricor.ACTICamWrapperJNI 重命名为 HelloWorld,要么将本机函数(在C++文件中)从 Java_HelloWorld_displayMessage() 重命名为 Java_au_com_ricor_ACTICamWrapperJNI_displayMessage()
我知道
这有一个答案,但我确定如果你作为调试编译,它不能再发行到另一台 PC; 您可以尝试编译发布,这应该有效。 我只是用它来解决我自己的问题。
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- 在 Ubuntu 18.04 上,我编译的 cpp 可执行文件找不到 VTK7 依赖项
- 项目 A 依赖共享库 B,B 依赖 C,A 不依赖 C。当我使用 B 的 API 时,警告 B 找不到 C
- Windeployqt 找不到所有的依赖项
- 找不到 CMake 静态库的依赖项
- Maven NAR插件:在路径上找不到DLL依赖项
- 使用Visual Studio 11 RC调试时找不到DLL依赖项
- DLL 无法加载:0x8007007E找不到模块。不确定导致此依赖项问题的原因
- JNI HellowWorld 不满意链接错误 找不到依赖库
- PInvoke-找不到指定的模块.如何检查缺少的依赖项
- 找不到标识符,即使使用依赖于参数的查找和运算符<<也不明确
- 为什么这个基于 JNI 的 JBoss 模块会抛出错误"找不到依赖库"?