2

I am building a first working version of a JNI application in C++. I do not believe the specific details of the application are important for this question. If they are, I will append them.

My code compiles without error. However, there is a single linker error:

error LNK2019: unresolved external symbol __imp__JNI_CreateJavaVM@12

I understand that JNI_CreateJavaVM is not included in jvm.lib / jvm.dll. However, I cannot determine what library I do need to link to for this function.

I have JDK installed (but only 64-bit - and this is a 32-bit C++ application, which may be relevant).

Can somebody please assist?

Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
  • 6
    `I have JDK installed (but only 64-bit - and this is a 32-bit C++ application, which may be relevant).` I think thats your answer. Try downloading the 32-bit JDK. – Jesse Good Apr 25 '12 at 04:22
  • That was it. Quite obvious even as I wrote it. I appreciate the quick response. – Dan Nissenbaum Apr 25 '12 at 05:42
  • Possible duplicate of [undefined reference to \`JNI\_CreateJavaVM' windows](http://stackoverflow.com/questions/16930567/undefined-reference-to-jni-createjavavm-windows) – Alex Cohn Oct 26 '15 at 20:37

2 Answers2

1

Steps to link the jvm.lib to your project in Visual Studio:

  • Right click on the project -> properties.
  • On the Properties dialog box, add jvm.lib under Linker->Input->AdditionalDependencies area.
  • Lastly write jvm.lib path(like "C:\Program
    Files\Java\jdk1.7.0_60\lib") under
    Linker->General->AdditionalLibraryDirectories

After those steps, your project can link to jvm and work well.

Mustafa Kemal
  • 1,292
  • 19
  • 24
0

If you want to run a Java application from C++ I suggest using exec and creating a new process esp if one is 32-bit and the other 64-bit.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Actually, it is easy enough for me to install & run a 32-bit JDK/JRE. Were I forced to do without 32-bit JRE, I would probably use sockets, as my C++ and Java components need to communicate. – Dan Nissenbaum Apr 25 '12 at 05:37
  • Sockets are a good way to communicate and if there is a problem with the process for some reason, you can kill it safely. – Peter Lawrey Apr 25 '12 at 07:13