JNI_CreateJavaVM使c++应用程序崩溃,没有错误消息
JNI_CreateJavaVM crashes C++ application without error message
我想在c++应用程序中使用voice。现在,在voice header中,更具体地说是void init()
中有这样一个部分:
vm_args.nOptions = 2;
// Setup the VM options.
// TODO: check out other options to be used here, like disabling the
// JIT compiler.
JavaVMOption options[2];
// Add the required Java class paths.
std::string classPathString = "-Djava.class.path=";
classPathString += vocePath;
classPathString += "/voce.jar";
char s[1024];
sprintf(s, classPathString.c_str());
options[0].optionString = s;
options[0].extraInfo = NULL;
// Add an option to increase the max heap size. (1)
char x[1024] = "-Xmx256m";
options[1].optionString = x;
options[1].extraInfo = NULL;
//options[1].optionString = "-Djava.compiler=NONE"; // Disable JIT.
//options[1].optionString = "-verbose:gc,class,jni";
vm_args.options = options;
//vm_args.ignoreUnrecognized = JNI_FALSE;
// Create the VM. (2)
status = JNI_CreateJavaVM(&internal::gJVM, (void**)&internal::gEnv, &vm_args);
如果我尝试像这样运行它,它会崩溃。如果我将所有内容放在(1)之后的注释中,它就会运行。之后,如果我将JNI_CreateJavaVM放入注释(2)中,它也可以运行。如果我直接从崩溃跳转到在注释中放入(2),它又会崩溃。我需要在(1)和(2)上取路径,然后只取(2)。然而,由于voice需要那个JavaVM,这是一个问题。显然。我的猜测是,我需要一些dll,目前我有jvm.dll在同一文件夹中的main.cpp,但不像voice .h.
如果对安装的jvm.dll使用动态链接和加载,应该可以正常工作。
typedef jint(JNICALL *pCreateJavaVM)(JavaVM **, void**, void *);
HINSTANCE hInstance = LoadLibrary(L"C:\Program Files\Java\jre1.8.0_77\bin\server\jvm.dll");
pCreateJavaVM CreateJavaVM = (pCreateJavaVM)GetProcAddress(hInstance, "JNI_CreateJavaVM");
jint res = CreateJavaVM(&vm, (void **)&env, &vm_args);
相关文章:
- C++错误消息*成员参考.**初学者*
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 如何通过参数抛出错误消息
- glad 导致 glfwSwapBuffers 返回错误消息
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 重新定义预定义的 errno 错误消息 (E2BIG)
- SDL 映像:无法打开映像,仅显示错误消息
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 我的代码中有错误,未声明的标识符
- 错误消息"expected expression"....有人知道它为什么这么说吗?
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- GCC 警告和 gcc 错误消息之间的区别
- 为 c++ cin 上的输入数无效生成错误消息
- 来自带有mbedtls TLS的Mongoose Web服务器的错误消息
- 如何使用realsense摄像头调试ROS错误消息
- C++ 概念 - 需要括号中的概念会导致 2 条冲突的错误消息
- 为什么从不同分配器的列表中剪辑列表元素时会有错误消息?以及如何解决
- Bada IDE有代码完成和有意义的错误消息吗?
- 为什么C++编译器有模糊的错误消息