运行一个非常简单的Hello World JNI测试时遇到麻烦
Trouble running a very simple Hello World JNI test
EDIT3:这是公然的编译器标志导致的问题,如果我从命令行编译使用微软的编译器它工作正常。有人知道我需要改变代码::块来解决这个问题吗?
当我运行我的代码,我得到一个UnsatisfiedLinkError。加载步骤工作正常,当它实际调用代码时,我得到错误。
从我的dll路径开始
java -Djava.library.path=E:JavaJNIHellowWorldPasswordGenHWbinDebug -jar distJNIHellowWorld.jar
异常
Exception in thread "main" java.lang.UnsatisfiedLinkError: jnihellowworld.Main.HelloWorld()Ljava/lang/String;
at jnihellowworld.Main.HelloWorld(Native Method)
at jnihellowworld.Main.main(Main.java:16)
Java代码package jnihellowworld;
import java.io.IOException;
public class Main {
public native String HelloWorld() throws Error;
public static void main(String[] args) throws IOException {
try
{
System.loadLibrary("PasswordGenHW");
String test = new Main().HelloWorld(); //errors on this line
System.out.println(test);
System.in.read();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
c++头/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jnihellowworld_Main */
#ifndef _Included_jnihellowworld_Main
#define _Included_jnihellowworld_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: jnihellowworld_Main
* Method: HelloWorld
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_jnihellowworld_Main_HelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
c++ cpp #include "jnihellowworld_Main.h"
#include <jni.h>
JNIEXPORT jstring JNICALL Java_jnihellowworld_Main_HelloWorld
(JNIEnv *env, jobject obj)
{
return env->NewStringUTF("Hello world!");
}
我正在使用Code::Blocks和GCC来完成dll。
编辑:这里是dll的dumpbin/exports
2 1 000011D8 Java_jnihellowworld_Main_HelloWorld@8
EDIT2:使用system.loadLibrary()简化项目以复制错误
尝试在编译和链接上添加这些标志:
-Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at
的例子:
gcc -c -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at test.c
gcc -shared -D_JNI_IMPLEMENTATION_ -Wl,--kill-at test.o -o mylib.dll
最后我只能用微软的编译器手工编译
相关文章:
- 通过JNI传递数据数组的最快方法是什么
- 无法编译wxWidgets Hello World
- 简单C++"Hello World"程序的执行时间长
- 使用 AWS Lambda 触发C++文件 - Hello World
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 将 C# DLL 导入 C++ 以用于 JNI
- 用C++包装 Java 库 (JNI)
- 使用 Visual Studio 2019 构建 Hello World wxwidgets 应用程序时出错
- 我怎样才能在行尾使用 cout<<"hello world";不使用 ;
- 如何通过 JNI 将 C 字符串表情符号传递给 Java
- JNI从Android调用C++方法
- JVM 如何执行 JNI
- React Native (Android):无法通过 JNI 在 jobject 中返回字符串
- QWebSocket Hello World Example
- 为什么下面的Hello World程序在PowerShell上没有显示任何输出?同一程序在CMD上显示正确的输出
- 如何将字符串数组返回到 java JNI
- JNI 日期值转换问题,在C++中获取不同的长整型值
- 与jni一起展示hello world swing
- 安卓"hello world"应用程序在C++没有JNI
- 运行一个非常简单的Hello World JNI测试时遇到麻烦