以下是我使用的代码和编译命令。我对c ++有些新意,并且真的不知道如何调试分段错误,并没有真正提供太多信息。任何建议将不胜感激!
#include <jni.h> /* where everything is defined */
int main() {
JNIEnv *env1;
JavaVM** jvm1;
JavaVMInitArgs vm_args1;
JavaVMOption options1[3];
options1[0].optionString = "-Djava.library.path=/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server/";
options1[1].optionString = "-Djava.class.path=.";
options1[2].optionString = "-Dulimit -c unlimited";
options1[0].extraInfo = NULL;
options1[1].extraInfo = NULL;
options1[2].extraInfo = NULL;
vm_args1.version = JNI_VERSION_1_6;
vm_args1.nOptions = 3;
vm_args1.options = options1;
vm_args1.ignoreUnrecognized = 0;
int reAt = JNI_CreateJavaVM(jvm1, (void**)&env1, &vm_args1);
return 0;
}
据我所知,导致问题的一行是JNI_CreateJavaVM行,当被注释掉时没有分段错误
要编译已尝试过这两种方法:
g ++ -g main.cpp -I / usr / lib / jvm / java-7-oracle / include -I / usr / lib / jvm / java-7-oracle / include / linux -L / usr / lib / jvm / java-7-oracle / jre / lib / amd64 / server -ljvm
g ++ -I / usr / lib / jvm / java-7-oracle / include -I / usr / lib / jvm / java-7-oracle / include / linux / -L / usr / lib / jvm / java- 7-oracle / jre / lib / amd64 / server main.cpp -l jvm -Wl,-rpath,/ usr / lib / jvm / java-7-oracle / jre / lib / amd64 / server -o a2.out