1

I'm working on a basic application to create a Java VM and launch a Java program from C++ with JNI. However, I have some compiling errors:

Error   6   error LNK2028: unresolved token (0A00000D) "extern "C" long __stdcall JNI_CreateJavaVM(struct JavaVM_ * *,void * *,void *)" (?JNI_CreateJavaVM@@$$J212YGJPAPAUJavaVM_@@PAPAXPAX@Z) referenced in function "public: bool __clrcall JarLauncher::launchJar(void)" (?launchJar@JarLauncher@@$$FQ$AAM_NXZ)  
Error   5   error LNK2028: unresolved token (0A00000C) "extern "C" long __stdcall JNI_GetDefaultJavaVMInitArgs(void *)" (?JNI_GetDefaultJavaVMInitArgs@@$$J14YGJPAX@Z) referenced in function "public: bool __clrcall JarLauncher::launchJar(void)" (?launchJar@JarLauncher@@$$FQ$AAM_NXZ)      
Error   7   error LNK2019: unresolved external symbol "extern "C" long __stdcall JNI_GetDefaultJavaVMInitArgs(void *)" (?JNI_GetDefaultJavaVMInitArgs@@$$J14YGJPAX@Z) referenced in function "public: bool __clrcall JarLauncher::launchJar(void)" (?launchJar@JarLauncher@@$$FQ$AAM_NXZ)   
Error   8   error LNK2019: unresolved external symbol "extern "C" long __stdcall JNI_CreateJavaVM(struct JavaVM_ * *,void * *,void *)" (?JNI_CreateJavaVM@@$$J212YGJPAPAUJavaVM_@@PAPAXPAX@Z) referenced in function "public: bool __clrcall JarLauncher::launchJar(void)" (?launchJar@JarLauncher@@$$FQ$AAM_NXZ)   
Error   9   error LNK1120: 4 unresolved externals   

Any help?

Klayderpus
  • 13
  • 6
  • Those are linker errors, not compiler errors. It's telling you you're missing some symbols. You either need to to provide implementations or get them for a library. – Carl Norum Jan 21 '13 at 07:30
  • Seems you did forget to link the library where those two functions reisde. – Arne Mertz Jan 21 '13 at 07:30
  • The JDK provides two .lib files which are both attached to the linker. I've attached jvm.lib and jawt.lib (even though I probably don't need the latter) – Klayderpus Jan 21 '13 at 07:34

1 Answers1

0

It looks like you didn't link jvm.lib. You usually find it in %ProgramFiles%\Java\jdk1.X.XX_XX\lib, then you can add it to your linker input settings.

Also, you'll need to load jvm.dll at runtime (and add it to the delay loaded dlls). On Windows, you can get the current location from the registry. Query SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion for the current runtime version and SOFTWARE\JavaSoft\Java Runtime Environment\<version>\RuntimeLib for the path of jvm.dll.

Using those paths you can also check if the required runtime version is present on the system.

Botz3000
  • 39,020
  • 8
  • 103
  • 127
  • The path is apparently C:\Program Files\Java\jre6\bin\client\jvm.dll, but the directory C:\Program Files\Java\jre6\bin\client doesn't exist... – Klayderpus Jan 21 '13 at 07:49
  • @Klayderpus That is weird, are you sure java is installed correctly? On my system it's exactly in that location. – Botz3000 Jan 21 '13 at 07:50
  • I'll do a a fresh install of the JRE and JDK in the morning...it's currently 3am and I need some sleep. Thanks for the help. – Klayderpus Jan 21 '13 at 07:52