Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile simple "Hello World" Java application with native-image on Windows

I'm trying to compile a simple Java Hello World application to native code using the native-image utility provided by GraalVM on Windows but I always run into errors (see below).

HelloWorld.java:

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

First, I compile the code to a class file using the following command:

>javac HelloWorld.java

Next, I invoke the native-image command from the VS 2017 Developer Command Prompt:

>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

I also tried the Windows SDK 7.1 Command Prompt and the VS 2019 version but neither worked. How can this issue be fixed? It can't be the compiler since it works for regular C/C++ applications. Is there anything else you need to configure for this?

like image 419
BullyWiiPlaza Avatar asked Nov 15 '22 18:11

BullyWiiPlaza


1 Answers

I managed to compile successfully using JDK 11 and the respective version of GraalVM. A visual guide for this can e.g. be found here (note: I'm the video uploader).

like image 173
BullyWiiPlaza Avatar answered Jan 04 '23 23:01

BullyWiiPlaza