I am trying to call / execute java jar from a C ++ program .
Here are the options I have found so far:
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
I would like to use JNI, but I have problems.
==========================
hello.cpp
I have a simple Hello.cpp class:
#include <iostream>
#include <jni.h>
using namespace std;
int main() {
cout << "Hello World" << endl;
JavaVM *jvm;
JNIEnv *env;
JDK1_1InitArgs vm_args;
vm_args.version = 0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
vm_args.classpath = "/home/FinishedJars/HelloWorld/hello2.jar";
JNI_CreateJavaVM(&jvm, &env, &vm_args);
jclass cls = env->FindClass("Main");
jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
env->CallStaticVoidMethod(cls, mid, 100);
jvm->DestroyJavaVM();
return 0;
}
==========================
Compile
And when I try to compile something like:
g++ -I /usr/lib/jvm/jdk1.6.0_34-x86/include/ Hello.cpp
Note. I found "jni.h" in this folder, so I included it. I assume this is correct, but I am not sure.
I get a lot of errors (see below)
==========================
Mistakes
I get a million errors from jni.h, as if it is trying to compile 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â
==========================
Additional Information:
eclipse, gcc-, hello, .
jni- :
â â C/++ â â â GNU ++ â â
, jni.h
, eclipse .
, Ubuntu 10 64bit...
========================
- ?
, ,
========================
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
========================
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
, :
( )
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
ERROR:
Hello.cpp:23: undefined reference to `JNI_GetDefaultJavaVMInitArgs'
Hello.cpp:27: undefined reference to `JNI_CreateJavaVM'
& env (void **) & env, ldav1s,
========================
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
...
========================
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
!