GraalVM native image on Windows
Installation
Original guide for Linux-like environments.
-
Download and install Microsoft Windows SDK for Windows 7
-
Make you there are no Microsoft Visual C++ 2010 Redistributable packages installed. If there are, uninstall them all (for both x86 and x 64).
If the 2010 Redistributable packages are already present during the installation the installation fails with message
Installation of the “Microsoft Windows SDK for Windows 7” product has reported the following error: Please refer to Samples\Setup\HTML\ConfigDetails.htm document for further information.
Please attempt to resolve the problem and then start Windows SDK setup again. If you continue to have problems with this issue, please visit the SDK team support page at http://go.microsoft.com/fwlink/?LinkId=130245.
- Mount the iso image and invoke
Setup\SDKSetup.exe
-
Options Windows Native Code Development and Redistributable Packages > Microsoft Visual C++ 2010 are sufficient.
-
-
Download and extract Windows GraalVM Preview. The website my require authentication.
Image creation
-
Create a source file
Foo.java
public class Foo { public static void main(String[] args) { System.out.println("Hello world!"); } }
-
Compile the source
<graalvm-dir>\bin\javac.exe Foo.java
-
Create the native image
- Open Windows SDK 7.1 Command Prompt in start menu. It is installed as part of Windows SDK for Windows 7.
-
Invoke the compilation from there
<graalvm-dir>\bin\native-image.cmd Foo
If the output looks like
>..\..\opt\graalvm\graalvm-ee-1.0.0-rc16-snapshot\bin\native-image.cmd Foo [foo:1276] classlist: 2,954.67 ms [foo:1276] (cap): 491.65 ms [foo:1276] setup: 1,062.71 ms Error: Unable to compile C-ABI query code. Make sure GCC toolchain is installed on your system. Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception Error: Image build request failed with exit status 1
then the Windows SDK is most likely not propertly installed or the
native-image.cmd
is not invoded from Windows SDK 7.1 Command PromptWhen the compilation finishes the directory content should look like this
30.04.2019 14:45 <DIR> . 30.04.2019 14:45 <DIR> .. 29.04.2019 17:03 407 Foo.class 30.04.2019 14:45 7 919 104 foo.exe 30.04.2019 14:45 1 541 955 foo.exp 11.04.2019 11:10 120 Foo.java 30.04.2019 14:45 2 534 272 foo.lib 30.04.2019 14:45 2 124 800 foo.pdb
Resulting binary
foo.exe
is a selfcontained executable consisting of Substrate JVM and AOT compiled application code.