0

I am trying to develop and debug a C++ program using Eclipse CDT. The program uses java Native Interface (JNI).

When JNI_CreateJavaVM() is called, the program crashes. If the program is run through the command line, it is successful.

The program is mostly from this tutorial

main.cpp

#include <iostream>
#include <jni.h>

int main()
{
    JavaVM *jvm;
    JNIEnv *env;

    JavaVMInitArgs vm_args;
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 0;
    vm_args.options = NULL;

    vm_args.ignoreUnrecognized = false;
    jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if (rc != JNI_OK) {
       std::cin.get();
       exit(EXIT_FAILURE);
    }
    jint ver = env->GetVersion();
    std::cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << std::endl;

   jvm->DestroyJavaVM();
}

Makefile:

CFLAGS =-c -Wall
EXECUTABLE=testProject
CC=g++
SOURCES= main.cpp
OBJECTS=$(SOURCES:.cpp=.o)

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(OBJECTS) -o $@ -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@ -g -I/usr/lib/jvm/java-8-openjdk-amd64/include -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux

clean:
    rm -rf *.o testProject

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.