cl.exe missing when building native app using GraalVM

19.5k views Asked by At

I'm trying to build a native application using GraalVM and native-image. An error occures when starting the build process. It seems the cl.exe is missing in the classpath. Like mentioned on the GraalVM website, i've installed the "GRMSDKX_EN_DVD.iso" (Windows SDK for Windows 7 and .NET). I've also tried installing the Windows SDK for Windows 10.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>native-image -jar C:\Users\tm\Desktop\DemoGraalVM\target\Demo-1.0-SNAPSHOT.jar
[Demo-1.0-SNAPSHOT:28776]    classlist:   2,435.83 ms,  1.16 GB
[Demo-1.0-SNAPSHOT:28776]        setup:     646.59 ms,  1.16 GB
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

I'm using windows 10, graalvm-ce-java8-windows-amd64-20.2.0. I'm also running Visual Studio Community Edition and use the Visual Studio 2019 Developer Command Prompt v16.3.1. The Java application is build in IntelliJ Community Edition using Maven.

How can I fix this? Where do I download the cl.exe or which installation package contains this file?

5

There are 5 answers

2
tmmls On BEST ANSWER

After 2 years struggling I gave up on trying to use GraalVM to build native executables. I now use the jPackage command line tool. It comes by default with the latest versions of Java. Works like a charm. No hassle, no additional dependencies, no errors, free, ...

More info: https://youtu.be/ZGW9AalZLN4

2
jdevp2 On

You'll need to set up the environment for Microsoft Visual C++.

I'm using Visual Studio 2017, so I have to use: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat

3
Zach On

I'm sorry you're having trouble; hopefully, we can nip that in the bud real fast!
It looks like you're missing some dependencies, so I'll do my best to clear the issue up for you.


To build a native GraalVM image on Windows, you'll need Microsoft Visual C++ (MSVC). The version required depends on the JDK version that your GraalVM distribution is based on.

  • For a GraalVM distribution using Java 8, you'll need MSVC 2010 SP1

    The recommended installation method is using Microsoft Windows SDK 7.1:

    1. Download the SDK file GRMSDKX_EN_DVD.iso for from Microsoft.
    2. Mount the image by opening F:\Setup\SDKSetup.exe directly.

    According to the GraalVM native-image reference, you can get this easily via the Window SDK 7.1 image from Microsoft

  • For a GraalVM distribution using Java 11, you need MSVC 2017 15.5.5 or later.
    I would definitely recommend just going with the latest version (currently 2019) unless you already use another version in your workflow. You can get it here.


Once you've installed Visual Studio, all of your build commands should be run through the Native Tools Command Prompt.
If you keep the default Start Menu shortcuts while installing Visual Studio, this will be accessible at:
Start -> Visual Studio 2019 -> Tools -> x64 Native Tools Command Prompt


Given that your code is in order, using the proper toolchain will resolve your issues. If any other problems arise, I encourage you to post another question for them; good luck with your project!

2
Gnosis00 On

Quick Guide

  1. Install Visual Studio (Microsoft Visual C++ must be selected)
  2. Download GraalVM and extract.
  3. Set env GRAALVM_HOME as where the graalvm located.
  4. Edit %GRAALVM_HOME%\bin\native-image.cmd
  5. Add following line to the very top

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsx86_amd64.bat"

Note: vcvarsx86_amd64.bat location may be different depending on your VS version.

0
benchdollar On

(Thanks fo @Gnosis00's and @Zach's solution. It almost worked for me. Here is an improved version that makes native builds also from within IDEA IntelliJ possible.)

Modify native-image.cmd (in your %JAVA_HOME%\bin directory) with a text editor such that it starts with

@echo off

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" > nul

This automatically adds the needed build toolchain every time native-build is invoked. You don't have to start it from Visual Studio's Native Tools Command Prompt anymore.

Please be aware of the ending > nul to suppress any output of vcvars64.bat. Otherwise, the version detection of GraalVM by Spring Boot's Gradle build scripts will fail.

This solution is tested with Microsoft Visual Studio 2022 CE, IDEA IntelliJ 2022.1.3 and graalvm-ce-java17-windows-amd64-22.3.1.