title: Calling Java Methods from Visual C/C++ using C++/CLI
body: <p>I'm getting a "error LNK1104: cannot open file {path}\jvm.lib" when trying tocompile a VS C++/CLI (managed) project. It's very simple and my goal is to call some Java methods in pre-existing java libs - here is the code I'm using: </p>
  
  <pre><code>// This is the main DLL file.
  
  #include "stdafx.h"
  #include &lt;jni_md.h&gt;
  #include &lt;jni.h&gt;
  #include "JBridge.h"
  
  #pragma once
  
  using namespace System;
  
  namespace JBridge 
  {
  
  public ref class JniBridge
  {
      // TODO: Add your methods for this class here.
  
  
  public:
      void HelloWorldTest()
      {
          System::Console::WriteLine("Hello Worldl from managed C++!");
      }
  
      JNIEnv* create_vm(JavaVM ** jvm) 
      {
          JNIEnv *env;
          JavaVMInitArgs vm_args;
  
          JavaVMOption options; 
          //Path to the java source code     
          options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; 
          vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
          vm_args.nOptions = 1;
          vm_args.options = &amp;options;
          vm_args.ignoreUnrecognized = 0;
  
          int ret = JNI_CreateJavaVM(jvm, (void**)&amp;env, &amp;vm_args);
          if(ret &lt; 0)
              printf("\nUnable to Launch JVM\n");       
          return env;
      }
      };
  }
  </code></pre>
  
  <p>I've verified the file does exist in the path location and I've added it to the project properties for the include dir and the linker property pages.</p>
  
  <p><strong>Update</strong>
  Got the jvm.lib to be linked with a bit more fiddling. </p>
  
  <p>Compilation causes following errors during build: </p>
  
  <p>Error   1   error LNK2028: unresolved token (0A00000A) "extern "C" long __stdcall JNI_CreateJavaVM(struct JavaVM_ * *,void * *,void *)" (?JNI_CreateJavaVM@@$$J212YGJPAPAUJavaVM_@@PAPAXPAX@Z) referenced in function "struct JNIEnv_ * __cdecl create_vm(struct JavaVM_ * *)" (?create_vm@@$$FYAPAUJNIEnv_@@PAPAUJavaVM_@@@Z)  c:\Temp\CLRTest\JBridge\JBridge\JBridge.obj JBridge
  Error   2   error LNK2019: unresolved external symbol "extern "C" long __stdcall JNI_CreateJavaVM(struct JavaVM_ * *,void * *,void *)" (?JNI_CreateJavaVM@@$$J212YGJPAPAUJavaVM_@@PAPAXPAX@Z) referenced in function "struct JNIEnv_ * __cdecl create_vm(struct JavaVM_ * *)" (?create_vm@@$$FYAPAUJNIEnv_@@PAPAUJavaVM_@@@Z)   c:\Temp\CLRTest\JBridge\JBridge\JBridge.obj JBridge
  Error   3   error LNK1120: 2 unresolved externals   c:\temp\CLRTest\JBridge\Debug\JBridge.dll   JBridge</p>