Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help...I'm dying here.

 
Mike Burton
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following error ad-infinitum:
error LNK2001: unresolved external symbol __imp__JNI_CreateJavaVM@12
When I comment the line out calling the JNI_CreateJavaVM() it compiles and links so I know DestroyJavaVM() is compiling-linking properly. Why would one method link and another not? I used Depends to see if the method was sitting in the jvm.dll, (and it is). Any help will be monetarily rewardable!
#include "stdafx.h"
#include <jni.h>
extern "C"
{
int main(int argc, char* argv[])
{
JavaVM* vm = NULL;
void* env = NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[4];
options[0].optionString = "-Djava.compiler=NONE";options[1].optionString = "-Djava.class.path=c:\\myclasses";options[2].optionString = "-Djava.library.path=c:\\mylibs";options[3].optionString = "-verbose:jni";/* print JNI-related messages */
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_TRUE;
jint nRet1 = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);
jint nRet2 = vm->DestroyJavaVM();
return 0;
}
}
 
Natalia Peysock
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have the same problem.
What did you do to resolve an issue?
 
Natalia Peysock
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to compile:
cl -Ic:\j2sdk1.4.2_10\include -Ic:\j2sdk1.4.2_10\include\win32 -MD Sample2.cpp -FeRunMain.exe -link "C:\j2sdk1.4.2_10\lib\jvm.lib"

Where Sample2.cpp is:

#include <jni.h>
#include <string.h>

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif

int main()
{
printf("Start C++ application\n");

JavaVMOption options[1];
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
long status;
jclass cls;
jmethodID mid;
jint square;
jboolean not;

options[0].optionString = "-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 1;
vm_args.options = options;

printf("Try to create JVM\n");

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

printf("JVM function returned");

if (status != JNI_ERR)
{
cls = env->FindClass("Sample2");
if(cls !=0)
{
mid = env->GetStaticMethodID(cls, "intMethod", "(I)I");
if(mid !=0)
{ square = env->CallStaticIntMethod(cls, mid, 5);
printf("Result of intMethod: %d\n", square);
}

mid = env->GetStaticMethodID(cls, "booleanMethod", "(Z)Z");
if(mid !=0)
{ not = env->CallStaticBooleanMethod(cls, mid, 1);
printf("Result of booleanMethod: %d\n", not);
}
}

jvm->DestroyJavaVM();
return 0;
}
else
{
return -1;
}
}

RunMain.exe is generated.

But now I have another problem. Program crashes at line:
status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
 
H. J. Yoshi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Facing the same errors..



I am using Microdosft VC++ 6.0 to build the exe.And have the lib files, header files in the build path.. still get this error..


any help is most welcome.

Thanks in advance
 
Natalia Peysock
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried many different approaches, and nothing worked. At the end, I found the following web site with instructions on how to build Visual C++ / Java interface. This web site helped me.

http://www.codeproject.com/cpp/integratingcppjava.asp

Good luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic