Visual C++ Error: LNK2019, LNK2028 and LNK1120

我们两清 提交于 2019-12-20 03:53:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14434096/visual-c-error-lnk2019-lnk2028-and-lnk1120

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!