4

I'm trying to create JVM usin JNI. I'm using win 7 64 bits OS. On line JNI_CreateJavaVM my program crashes. I decided to compile my program using 64 bit compiler and got following error:

Error 1 error LNK2001: unresolved external symbol __imp_JNI_CreateJavaVM

Where is the point I should start to look for linking problem and why my program crashes in 32 bit mode?

void createJVM()
{

JavaVMInitArgs vm_args; 
JavaVMOption options[4]; 

int n = 0;     
char * str;
str= new char[1000];
sprintf(str, "-Djava.class.path=%S\\tst.jar", myPath);
options[n++].optionString = str; 

str= new char[1000];
sprintf(str, "-Djava.library.path=%S\\lib;%S", myPath, myPath);
options[n++].optionString = str;

str= new char[1000];
sprintf(str, "-Duser.dir=%S", myPath);
options[n++].optionString = str;

vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = n;     
vm_args.options = options;     
vm_args.ignoreUnrecognized = false;


JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); 
}
Andreas
  • 5,393
  • 9
  • 44
  • 53
vico
  • 17,051
  • 45
  • 159
  • 315

2 Answers2

4

have you added 'jvm.lib' as Additional Dependency in your project? furthermore, you need to specify the location of jvm.lib in Additional Library Directories...

also please note that for 64-bit application, you would need to point to the 64-bit library, otherwise linker won't link

You can find those settings in the Configuration Properties->Linker area.

hope this information helps you out.

Cheers,

Naytzyrhc
  • 2,297
  • 26
  • 39
  • I added the path to the jvm.lib to the two project properties you mentioned but I still get this linker error. Do have any more hints? Do I need to add any Java DLL to the project or something? – Andreas Feb 06 '14 at 10:28
0

Since I can't wote up (still less than 15 reputation) I just want to confirm that Naytzyrhc solution worked for me.

Just to clarify it a bit more, in Visual Studio Express 2013 (v12) you should go to:

Project -> [YourProjectName] Properties... -> Linker -> General -> Additional Library Directories

for adding lib folder to additional library directories, and:

Project -> [YourProjectName] Properties... -> Linker -> Input -> Additional Dependencies

for adding jvm.lib to additional dependencies.

user2310395
  • 297
  • 3
  • 6