2013-03-22 25 views
2

我试图呼叫/从一个C++程序执行一个java 罐子。使用JNI执行从C++程序一个java罐,使用克++或蚀

这里是我到目前为止发现的选项:

Use JNI 
Use Jace 
Use JunC++ion 
Use execl("java", "java", "-jar", "myprog.jar", NULL); 
Use execlp("java", "java", "-jar", "myprog.jar", (char *)0); 
Use system("java filename.jar"); 
Use popen("java -jar test.jar text1 text2", "r"); 
Use CreateProcess(...); 
Use JNA 

我想使用JNI,但是我遇到了问题。

========================

HELLO.CPP

我有一个简单HELLO.CPP类:

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

using namespace std; 

int main() { 
     cout << "Hello World" << endl; // prints Hello World 

     JavaVM *jvm;  /* denotes a Java VM */ 
     JNIEnv *env;  /* pointer to native method interface */ 
     JDK1_1InitArgs vm_args; /* JDK 1.1 VM initialization arguments */ 
     vm_args.version = 0x00010001; /* New in 1.1.2: VM version */ 
     /* Get the default initialization arguments and set the class 
     * path */ 
     JNI_GetDefaultJavaVMInitArgs(&vm_args); 
     vm_args.classpath = "/home/FinishedJars/HelloWorld/hello2.jar"; 
     /* load and initialize a Java VM, return a JNI interface 
     * pointer in env */ 
     JNI_CreateJavaVM(&jvm, &env, &vm_args); 
     /* invoke the Main.test method using the JNI */ 
     jclass cls = env->FindClass("Main"); 
     jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V"); 
     env->CallStaticVoidMethod(cls, mid, 100); 
     /* We could have created an Object and called methods on it instead */ 
     /* We are done. */ 
     jvm->DestroyJavaVM(); 

    return 0; 
} 

========================

编译

,当我尝试的东西,如编译:

g++ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/ Hello.cpp 

注:我在该文件夹中找到了“jni.h”,所以我将它包含在内。我假设这是正确的地方,但我不能确定

我得到一吨的错误(见下文)

================= =======

错误

我从jni.h 百万错误,如果它试图编译jni.h:

/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetStaticLongField(_jclass*, _jfieldID*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1568: error: ‘const struct JNINativeInterface_’ has no member named ‘SetStaticLongField’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetStaticFloatField(_jclass*, _jfieldID*, jfloat)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1572: error: ‘const struct JNINativeInterface_’ has no member named ‘SetStaticFloatField’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetStaticDoubleField(_jclass*, _jfieldID*, jdouble)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1576: error: ‘const struct JNINativeInterface_’ has no member named ‘SetStaticDoubleField’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jstring* JNIEnv_::NewString(const jchar*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1580: error: ‘const struct JNINativeInterface_’ has no member named ‘NewString’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘const jchar* JNIEnv_::GetStringChars(_jstring*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1586: error: ‘const struct JNINativeInterface_’ has no member named ‘GetStringChars’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseStringChars(_jstring*, const jchar*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1589: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseStringChars’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jstring* JNIEnv_::NewStringUTF(const char*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1593: error: ‘const struct JNINativeInterface_’ has no member named ‘NewStringUTF’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘const char* JNIEnv_::GetStringUTFChars(_jstring*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1599: error: ‘const struct JNINativeInterface_’ has no member named ‘GetStringUTFChars’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseStringUTFChars(_jstring*, const char*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1602: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseStringUTFChars’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jobjectArray* JNIEnv_::NewObjectArray(int, _jclass*, _jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1611: error: ‘const struct JNINativeInterface_’ has no member named ‘NewObjectArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jobject* JNIEnv_::GetObjectArrayElement(_jobjectArray*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1614: error: ‘const struct JNINativeInterface_’ has no member named ‘GetObjectArrayElement’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetObjectArrayElement(_jobjectArray*, int, _jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1618: error: ‘const struct JNINativeInterface_’ has no member named ‘SetObjectArrayElement’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jbooleanArray* JNIEnv_::NewBooleanArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1622: error: ‘const struct JNINativeInterface_’ has no member named ‘NewBooleanArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jbyteArray* JNIEnv_::NewByteArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1625: error: ‘const struct JNINativeInterface_’ has no member named ‘NewByteArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jcharArray* JNIEnv_::NewCharArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1628: error: ‘const struct JNINativeInterface_’ has no member named ‘NewCharArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jshortArray* JNIEnv_::NewShortArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1631: error: ‘const struct JNINativeInterface_’ has no member named ‘NewShortArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jintArray* JNIEnv_::NewIntArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1634: error: ‘const struct JNINativeInterface_’ has no member named ‘NewIntArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jlongArray* JNIEnv_::NewLongArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1637: error: ‘const struct JNINativeInterface_’ has no member named ‘NewLongArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jfloatArray* JNIEnv_::NewFloatArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1640: error: ‘const struct JNINativeInterface_’ has no member named ‘NewFloatArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jdoubleArray* JNIEnv_::NewDoubleArray(int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1643: error: ‘const struct JNINativeInterface_’ has no member named ‘NewDoubleArray’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jboolean* JNIEnv_::GetBooleanArrayElements(_jbooleanArray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1647: error: ‘const struct JNINativeInterface_’ has no member named ‘GetBooleanArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jchar* JNIEnv_::GetCharArrayElements(_jcharArray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1653: error: ‘const struct JNINativeInterface_’ has no member named ‘GetCharArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jshort* JNIEnv_::GetShortArrayElements(_jshortArray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1656: error: ‘const struct JNINativeInterface_’ has no member named ‘GetShortArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jfloat* JNIEnv_::GetFloatArrayElements(_jfloatArray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1665: error: ‘const struct JNINativeInterface_’ has no member named ‘GetFloatArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jdouble* JNIEnv_::GetDoubleArrayElements(_jdoubleArray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1668: error: ‘const struct JNINativeInterface_’ has no member named ‘GetDoubleArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseBooleanArrayElements(_jbooleanArray*, jboolean*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1674: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseBooleanArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseByteArrayElements(_jbyteArray*, int*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1679: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseByteArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseCharArrayElements(_jcharArray*, jchar*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1684: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseCharArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseShortArrayElements(_jshortArray*, jshort*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1689: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseShortArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseIntArrayElements(_jintArray*, int*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1694: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseIntArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseLongArrayElements(_jlongArray*, int*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1699: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseLongArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseFloatArrayElements(_jfloatArray*, jfloat*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1704: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseFloatArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseDoubleArrayElements(_jdoubleArray*, jdouble*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1709: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseDoubleArrayElements’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetBooleanArrayRegion(_jbooleanArray*, int, int, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1714: error: ‘const struct JNINativeInterface_’ has no member named ‘GetBooleanArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetByteArrayRegion(_jbyteArray*, int, int, int*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1718: error: ‘const struct JNINativeInterface_’ has no member named ‘GetByteArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetCharArrayRegion(_jcharArray*, int, int, jchar*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1722: error: ‘const struct JNINativeInterface_’ has no member named ‘GetCharArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetShortArrayRegion(_jshortArray*, int, int, jshort*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1726: error: ‘const struct JNINativeInterface_’ has no member named ‘GetShortArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetIntArrayRegion(_jintArray*, int, int, int*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1730: error: ‘const struct JNINativeInterface_’ has no member named ‘GetIntArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetLongArrayRegion(_jlongArray*, int, int, int*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1734: error: ‘const struct JNINativeInterface_’ has no member named ‘GetLongArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetFloatArrayRegion(_jfloatArray*, int, int, jfloat*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1738: error: ‘const struct JNINativeInterface_’ has no member named ‘GetFloatArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetDoubleArrayRegion(_jdoubleArray*, int, int, jdouble*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1742: error: ‘const struct JNINativeInterface_’ has no member named ‘GetDoubleArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetBooleanArrayRegion(_jbooleanArray*, int, int, const jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1747: error: ‘const struct JNINativeInterface_’ has no member named ‘SetBooleanArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetByteArrayRegion(_jbyteArray*, int, int, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1751: error: ‘const struct JNINativeInterface_’ has no member named ‘SetByteArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1751: error: ‘buf’ was not declared in this scope 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetCharArrayRegion(_jcharArray*, int, int, const jchar*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1755: error: ‘const struct JNINativeInterface_’ has no member named ‘SetCharArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetShortArrayRegion(_jshortArray*, int, int, const jshort*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1759: error: ‘const struct JNINativeInterface_’ has no member named ‘SetShortArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetIntArrayRegion(_jintArray*, int, int, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1763: error: ‘const struct JNINativeInterface_’ has no member named ‘SetIntArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1763: error: ‘buf’ was not declared in this scope 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetLongArrayRegion(_jlongArray*, int, int, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1767: error: ‘const struct JNINativeInterface_’ has no member named ‘SetLongArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1767: error: ‘buf’ was not declared in this scope 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetFloatArrayRegion(_jfloatArray*, int, int, const jfloat*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1771: error: ‘const struct JNINativeInterface_’ has no member named ‘SetFloatArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::SetDoubleArrayRegion(_jdoubleArray*, int, int, const jdouble*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1775: error: ‘const struct JNINativeInterface_’ has no member named ‘SetDoubleArrayRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetStringRegion(_jstring*, int, int, jchar*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1798: error: ‘const struct JNINativeInterface_’ has no member named ‘GetStringRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::GetStringUTFRegion(_jstring*, int, int, char*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1801: error: ‘const struct JNINativeInterface_’ has no member named ‘GetStringUTFRegion’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void* JNIEnv_::GetPrimitiveArrayCritical(_jarray*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1805: error: ‘const struct JNINativeInterface_’ has no member named ‘GetPrimitiveArrayCritical’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleasePrimitiveArrayCritical(_jarray*, void*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1808: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleasePrimitiveArrayCritical’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘const jchar* JNIEnv_::GetStringCritical(_jstring*, jboolean*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1812: error: ‘const struct JNINativeInterface_’ has no member named ‘GetStringCritical’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::ReleaseStringCritical(_jstring*, const jchar*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1815: error: ‘const struct JNINativeInterface_’ has no member named ‘ReleaseStringCritical’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jobject* JNIEnv_::NewWeakGlobalRef(_jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1819: error: ‘const struct JNINativeInterface_’ has no member named ‘NewWeakGlobalRef’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void JNIEnv_::DeleteWeakGlobalRef(_jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1822: error: ‘const struct JNINativeInterface_’ has no member named ‘DeleteWeakGlobalRef’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jboolean JNIEnv_::ExceptionCheck()’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1826: error: ‘const struct JNINativeInterface_’ has no member named ‘ExceptionCheck’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘_jobject* JNIEnv_::NewDirectByteBuffer(void*, int)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1830: error: ‘const struct JNINativeInterface_’ has no member named ‘NewDirectByteBuffer’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘void* JNIEnv_::GetDirectBufferAddress(_jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1833: error: ‘const struct JNINativeInterface_’ has no member named ‘GetDirectBufferAddress’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: In member function ‘jobjectRefType JNIEnv_::GetObjectRefType(_jobject*)’: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1839: error: ‘const struct JNINativeInterface_’ has no member named ‘GetObjectRefType’ 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h: At global scope: 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1851: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1853: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1859: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1877: error: ‘JNICALL’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1877: error: ISO C++ forbids declaration of ‘jint’ with no type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1877: error: ‘jint’ declared as function returning a function 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1879: error: ‘JNICALL’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1879: error: ISO C++ forbids declaration of ‘jint’ with no type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1879: error: ‘jint’ declared as function returning a function 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1881: error: ‘JNICALL’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1881: error: ISO C++ forbids declaration of ‘jint’ with no type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1881: error: ‘jint’ declared as function returning a function 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1883: error: ‘JNICALL’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1883: error: ‘jint’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1883: error: ISO C++ forbids declaration of ‘jint’ with no type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1883: error: ‘jint’ declared as function returning a function 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1885: error: ‘JNICALL’ has not been declared 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1885: error: ISO C++ forbids declaration of ‘jint’ with no type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1885: error: ‘jint’ declared as function returning a function 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1892: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1895: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1898: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1902: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1905: error: ‘jint’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1916: error: ‘JNIIMPORT’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1919: error: ‘JNIIMPORT’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1922: error: ‘JNIIMPORT’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1926: error: ‘JNIEXPORT’ does not name a type 
/usr/lib/jvm/jdk1.6.0_34-x86/include/jni.h:1929: error: expected constructor, destructor, or type conversion before ‘void’ 
2013-03-21-1356-Hello-GCC-Ex.cpp: In function ‘int main()’: 
2013-03-21-1356-Hello-GCC-Ex.cpp:19: error: ‘JDK1_1InitArgs’ was not declared in this scope 
2013-03-21-1356-Hello-GCC-Ex.cpp:19: error: expected ‘;’ before ‘vm_args’ 
2013-03-21-1356-Hello-GCC-Ex.cpp:20: error: ‘vm_args’ was not declared in this scope 
2013-03-21-1356-Hello-GCC-Ex.cpp:23: error: ‘JNI_GetDefaultJavaVMInitArgs’ was not declared in this scope 
2013-03-21-1356-Hello-GCC-Ex.cpp:27: error: ‘JNI_CreateJavaVM’ was not declared in this scope 
2013-03-21-1356-Hello-GCC-Ex.cpp:34: error: ‘struct JavaVM_’ has no member named ‘DestroyJavaVM’ 

===== ===================

更多信息:

我与日食试过,通过创建创建可执行空GCC项目,创建我的Hello World代码,并能正常工作。

在那之后,我添加了JNI代码,并通过进口源:

右键项目 - >属性 - > C/C++常规 - >路径和符号 - >包括 - > GNU C++ - >添加 - >

然后添加包含jni.h

当我尝试建立这种方式,在Eclipse中,我得到确切同样的错误的目录。

另外,我在Ubuntu 10 64位运行...

========================

灿有人帮忙?

这可能是一个非常简单的进口问题,但我不知道

========================

更新1

运行:

g++ -I /usr/lib/jvm/jdk1.7.0_06/include/ -I /usr/lib/jvm/jdk1.7.0_06/include/linux/ Hello.cpp

给我:

Hello.cpp: In function ‘int main()’: 
Hello.cpp:19: error: ‘JDK1_1InitArgs’ was not declared in this scope 
Hello.cpp:19: error: expected ‘;’ before ‘vm_args’ 
Hello.cpp:20: error: ‘vm_args’ was not declared in this scope 

========================

UPDATE 2

显然JDK1_1InitArgs在JDK 6除去,所以编译在JDK 5 jni.h这样的:

g++ -I /usr/lib/jvm/jdk1.5.0_22-x86/include/ -I /usr/lib/jvm/jdk1.5.0_22-x86/include/linux/ Hello.cpp

,这让我:

Hello.cpp: In function ‘int main()’: 
Hello.cpp:24: warning: deprecated conversion from string constant to ‘char*’ 
Hello.cpp:27: error: invalid conversion from ‘JNIEnv**’ to ‘void**’ 
Hello.cpp:27: error: initializing argument 2 of ‘jint JNI_CreateJavaVM(JavaVM**, void**, void*)’ 

==================== ====

更新3

我一直在做一些研究和可能的解决方案是:

  1. Add -L/usr/X11R6/lib,或在前所未有的X11库,以 g ++命令......无影响。
  2. Add the paths of ibhpi.so and libjvm.so to the LD_LIBRARY_PATH(对我来说这是在/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/native_threads /)......没有效果
  3. Add libjava.so to the LD_LIBRARY_PATH以及(我是在/ usr /lib/jvm/jdk1.5.0_22-x86/jre/lib/i386 /)......没有效果
  4. 添加的jre/lib添加到LD_LIBRARY_PATH ......没有效果

我的一个最终编译命令(仍然不工作,虽然)

g++ -g 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/ 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/linux/ 
-L/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/ 
Hello.cpp 

错误:

Hello.cpp:23: undefined reference to `JNI_GetDefaultJavaVMInitArgs' 
Hello.cpp:27: undefined reference to `JNI_CreateJavaVM' 

我改变& ENV到(无效**)& ENV,由ldav1s建议摆脱空虚明星误差

=============== =========

UPDATE 4

我认为,问题是,我试图加载我的系统不建?库...

我现在的命令是:

g++ 
-L/usr/lib/jvm/jdk1.5.0_22-x86/lib 
-L/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib 
-L/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386 -ljava 
-L/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/native_threads -lhpi 
-L/usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/server -ljvm 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/ 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/linux/ 
Hello.cpp 

和我得到:

... 
/usr/bin/ld: skipping incompatible /usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/libjava.so when searching for -ljava 
/usr/bin/ld: skipping incompatible /usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/native_threads/libhpi.so when searching for -lhpi 
/usr/bin/ld: skipping incompatible /usr/lib/jvm/jdk1.5.0_22-x86/jre/lib/i386/server/libjvm.so when searching for -ljvm 
/usr/bin/ld: cannot find -ljava 
/usr/bin/ld: cannot find -lhpi 
/usr/bin/ld: cannot find -ljvm 
... 

======================= =

UPDATE 5 /解

我花了一段时间,但是这给了我的错误数最少的!

g++ -fPIC 
-L/usr/lib/jvm/java-6-openjdk/jre/lib 
-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -ljava -lverify 
-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/native_threads -lhpi 
-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -ljvm 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/ 
-I /usr/lib/jvm/jdk1.5.0_22-x86/include/linux/ 
Hello.cpp 

警告:

Hello.cpp: In function ‘int main()’: 
Hello.cpp:24: warning: deprecated conversion from string constant to ‘char* 

注意:在运行记住了AMD库添加到LD_LIBRARY_PATH前:

$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:$LD_LIBRARY_PATH 
$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/native_threads:$LD_LIBRARY_PATH 
$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:$LD_LIBRARY_PATH 
$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib:$LD_LIBRARY_PATH 

谢谢!

回答

5

通常你必须添加某种特定平台的目录,以及喜欢在Linux上:

g++ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/linux Hello.cpp 

因为一些宏(例如:JNICALL)设置在那里。希望这会解决jni.h错误级联。

编辑:仍卡住?尝试:

JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); 

它至少会超过编译问题。我不知道它是否会工作,因为我以前没有尝试过。

+0

太棒了!让我试试看... – Kayvar 2013-03-22 00:38:36

+0

哇!这显着帮助!我现在只有4个错误,而不是1000+。谢谢!现在我只需要找出其余的 – Kayvar 2013-03-22 00:44:06

+0

添加了一个提示,以通过错误。 – ldav1s 2013-03-22 03:55:47