我正在尝试使用Java
上GraalVM
提供的Hello World
实用程序将一个简单的native-image
Windows
应用程序编译为本机代码,但是我总是运行出现错误(请参见下文)。
HelloWorld.java
:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
首先,我使用以下命令将代码编译为class
文件:
>javac HelloWorld.java
接下来,我从VS 2017 Developer Command Prompt
调用native-image
命令:
>native-image -H:+ReportExceptionStackTraces HelloWorld
[helloworld:20420] classlist: 1,249.05 ms
[helloworld:20420] (cap): 704.71 ms
[helloworld:20420] setup: 997.16 ms
Error: Error compiling query code (in C:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.cpp). Compiler command CL -IC:\GraalVM\include\win32 C:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.cpp /FeC:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.exe output included error: [Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035 for x86, Copyright (C) Microsoft Corporation. All rights reserved., ]
com.oracle.svm.core.util.UserError$UserException: Error compiling query code (in C:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.cpp). Compiler command CL -IC:\GraalVM\include\win32 C:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.cpp /FeC:\Users\User\AppData\Local\Temp\SVM-2348968769537330415\JNIHeaderDirectives.exe output included error: [Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035 for x86, Copyright (C) Microsoft Corporation. All rights reserved., ]
at com.oracle.svm.core.util.UserError.abort(UserError.java:114)
at com.oracle.svm.hosted.c.NativeLibraries.reportErrors(NativeLibraries.java:218)
at com.oracle.svm.hosted.NativeImageGenerator.processNativeLibraryImports(NativeImageGenerator.java:1518)
at com.oracle.svm.hosted.NativeImageGenerator.setupNativeLibraries(NativeImageGenerator.java:1006)
at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:835)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:528)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Error: Image build request failed with exit status 1
我也尝试了Windows SDK 7.1 Command Prompt
和VS 2019
版本,但是都没有用。如何解决此问题?它不能用于编译器,因为它适用于常规C/C++
应用程序。您还需要为此配置什么吗?
答案 0 :(得分:0)
我设法使用JDK 11
和the respective version of GraalVM
成功地进行了编译。视觉指南可以例如被发现here(注意:我是视频上传者)。