title: How to generate a Java VM from C++ using cygwin on a 64-bit Windows 7?
body: <p>I am trying to create a Java virtual machine (JVM) from a C++ program. After researching I found that I need to call JNI_CreateJavaVM method to achieve it. Just to try I got the piece of code Michael Bruckmeier posted in this question <a href="https://stackoverflow.com/questions/2570551/it-wont-create-a-java-vm-jni">It won&#39;t create a Java VM (JNI)</a> changing very few things to avoid warnings.</p>
  
  <pre><code>#include &lt;jni.h&gt;  
  #include &lt;iostream&gt;  
  
  int main(int argc, char *argv[])  
  {  
      char optionStr[] = "-Djava.class.path=./build/java"; //Path to the java source code  
  
      JavaVM *jvm;  
      JNIEnv *env;  
      JavaVMInitArgs vm_args;  
      JavaVMOption options[1];  
      options[0].optionString = optionStr;  
      vm_args.version = JNI_VERSION_1_2;  
      vm_args.nOptions = 1;  
      vm_args.options = options;  
      vm_args.ignoreUnrecognized = 0;  
  
      jint ret = JNI_CreateJavaVM(&amp;jvm, (void**)&amp;env, &amp;vm_args);  
      std::cout &lt;&lt; "JNI_CreateJavaVM returned " &lt;&lt; ret &lt;&lt; std::endl;  
  
      return 0;  
  }  
  </code></pre>
  
  <p>I compile the previous program in gcc inside cygwin but I am getting some link errors:</p>
  
  <pre><code>$ gcc main.cpp /cygdrive/c/Progra~1/Java/jdk1.6.0_24/lib/jvm.lib -lstdc++ -o main  
  /tmp/ccKyd2Xk.o:main.cpp:(.text+0xfa): undefined reference to `_JNI_CreateJavaVM'  
  collect2: ld returned 1 exit status  
  </code></pre>
  
  <p>In order to check the symbol in the jvm.lib I used nm command and I got a very large list of these messages:</p>
  
  <pre><code>BFD: /cygdrive/c/Progra~1/Java/jdk1.6.0_24/lib/jvm.lib(jvm.dll): Recognised but  
  unhandled machine type (0x8664) in Import Library Format archive  
  nm: jvm.dll: File format not recognized  
  </code></pre>
  
  <p>I can guess the problem is that the Java Development Kit (JVM) is a 64-bit one. My OS is a 64-bit Windows 7, and the gcc is generating a 32-bit application. So, I think there is the incompatibility. I tried also to generate the app in 64-bit (although I would prefer having a 32-bit one) and this is the result:</p>
  
  <pre><code>$ gcc -m64 main.cpp /cygdrive/c/Progra~1/Java/jdk1.6.0_24/lib/jvm.lib -lstdc++ -o main  
  main.cpp:1: sorry, unimplemented: 64-bit mode not compiled in  
  </code></pre>
  
  <p>Can some one suggest a way to achiving having a JVM in C++ using this environment? Or in case I am wrong (that could be as well), could someone tell me why I am getting these errors?</p>
  
  <p>Thanks in advance!</p>