title: error: base operand of ‘->’ has non-pointer type ‘JNIEnv’
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;jni.h&gt;
  
   JNIEnv* create_vm() {
      JavaVM* jvm;
      JNIEnv* env;
      JavaVMInitArgs args;
      JavaVMOption options[1];
  
      /* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */
      args.version = JNI_VERSION_1_2;
      args.nOptions = 1;
      options[0].optionString = "-Djava.class.path=/home/test/workspace/pankajs/"
              "jikes/JikesRVMia32-linuxproduction/target/tests/stress/prototype/basic/classes";
      args.options = options;
      args.ignoreUnrecognized = JNI_FALSE;
  
      JNI_CreateJavaVM(&amp;jvm, (void **)&amp;env, &amp;args);
      return env;
  }
  
  void invoke_class(JNIEnv* env) {
      jclass helloWorldClass;
      jmethodID mainMethod;
      jobjectArray applicationArgs;
      jstring applicationArg0;
  
      helloWorldClass = (*env)-&gt;FindClass(env, "/test/org/jikesrvm/basic/core/bytecode/TestSwitch");
  
      mainMethod = (*env)-&gt;GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V");
  
      applicationArgs = (*env)-&gt;NewObjectArray(env, 1, (*env)-&gt;FindClass(env, "java/lang/String"), NULL);
      applicationArg0 = (*env)-&gt;NewStringUTF(env, "From-C-program");
      (*env)-&gt;SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
  
      (*env)-&gt;CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs);
  }
  
  
  int main(int argc, char **argv) {
      JNIEnv* env = create_vm();
      invoke_class( env );
  }
  
  I am trying to learn how JVM is actually invoked from bootstrap C files.
  </code></pre>
  
  <p>I found this example on internet and I am facing some problems while running it.</p>
  
  <p>I am properly specify the build commands as far as I know as,</p>
  
  <pre><code>  g++ -g -I /usr/lib/jvm/java-6-sun-1.6.0.26/include -I /usr/lib/jvm/java-6-sun-1.6.0.26/include/linux CallJVM.c
  </code></pre>
  
  <p>My intention is to actually run it using jikesrvm but to experiment this I chose
  to work with JVM.
  The error I am getting is :</p>
  
  <pre><code>CallJVM.c: In function ‘JNIEnv* create_vm()’:
  CallJVM.c:14:4: warning: deprecated conversion from string constant to ‘char*’
  CallJVM.c: In function ‘void invoke_class(JNIEnv*)’:
  CallJVM.c:28:26: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:30:21: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:32:26: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:32:57: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:33:26: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:34:8: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  CallJVM.c:36:8: error: base operand of ‘-&gt;’ has non-pointer type ‘JNIEnv’
  </code></pre>
  
  <p>I noticed the different ways of implementing in C and C++ but I think I am writing it correctly.</p>
  
  <p>Edit: On compiling with gcc ,I am getting </p>
  
  <pre><code>undefined reference to `JNI_CreateJavaVM'
  </code></pre>
  
  <p>and it is what was being prompted in eclipse but I thought my configurations are not apt.When I use <code>ctrl+click</code> it takes me to referenced jni.h as well but still why it is missing reference ?
  am specifically mentioning my folders on include path.</p>