Reputation: 530
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?
Upvotes: 27
Views: 21013
Reputation: 2488
If you came across this question being a Gradle user, here's a way to launch this build from PowerShell:
cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && .\gradlew build -Dquarkus.native.enabled=true -Dquarkus.package.jar.enabled=false'
Please make sure to have the single quotes around both commands, that is the batch file and gradlew
.
Please replace 2022
by your Visual Studio Build Tools version installed. To find which version(s) are installed on your systems, you can use WinGet:
winget list "build tools"
You should see something like
Name ID Version Source
-------------------------------------------------------------------------------------
Visual Studio Build Tools 2022 Microsoft.VisualStudio.2022.BuildTools 17.11.1 winget
To install Visual Studio Build Tools 2022, you can use:
winget install --exact --id Microsoft.VisualStudio.2022.BuildTools
Upvotes: 0
Reputation: 585
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:
- Download the SDK file
GRMSDKX_EN_DVD.iso
for from Microsoft.- 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!
Upvotes: 28
Reputation: 153
(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.
Upvotes: 13
Reputation: 337
GRAALVM_HOME
as where the graalvm located.%GRAALVM_HOME%\bin\native-image.cmd
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.
Upvotes: 9
Reputation: 530
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
Upvotes: 3
Reputation: 663
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
Upvotes: 0