Visual C++ 错误:LNK2019、LNK2028 和 LNK1120

Visual C++ Error: LNK2019, LNK2028 and LNK1120(Visual C++ 错误:LNK2019、LNK2028 和 LNK1120)

本文介绍了Visual C++ 错误:LNK2019、LNK2028 和 LNK1120的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基本应用程序,以创建 Java VM 并使用 JNI 从 C++ 启动 Java 程序.但是,我有一些编译错误:

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   

有什么帮助吗?

推荐答案

你好像没有链接jvm.lib.您通常可以在 %ProgramFiles%Javajdk1.X.XX_XXlib 中找到它,然后您可以将其添加到链接器输入设置中.

It looks like you didn't link jvm.lib. You usually find it in %ProgramFiles%Javajdk1.X.XX_XXlib, then you can add it to your linker input settings.

此外,您需要在运行时加载 jvm.dll(并将其添加到延迟加载的 dll 中).在 Windows 上,您可以从注册表中获取当前位置.在 SOFTWAREJavaSoftJava Runtime EnvironmentCurrentVersion 中查询当前运行时版本,在 SOFTWAREJavaSoftJava Runtime EnvironmentRuntimeLib 中查询 jvm 的路径.dll.

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 SOFTWAREJavaSoftJava Runtime EnvironmentCurrentVersion for the current runtime version and SOFTWAREJavaSoftJava 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.

这篇关于Visual C++ 错误:LNK2019、LNK2028 和 LNK1120的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Visual C++ 错误:LNK2019、LNK2028 和 LNK1120

基础教程推荐