Graal: Native Image "HelloWorld.java" Fails

Created on 18 Apr 2018  路  8Comments  路  Source: oracle/graal

I'm trying the HelloWorld.java native image example and am receiving a failure. Here is what I attempted:

HelloWorld.java:

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

command:
javac HelloWorld.java

Results in HelloWorld.class file generated.

command:
native-image HelloWorld

Results in the following failure:

Build on Server(pid: 10370, port: 26681)*
   classlist:   1,544.97 ms
       (cap):   3,572.68 ms
       setup:   4,269.92 ms
error: Error compiling query code (in /tmp/SVM-8237896470152817894/PosixDirectives.c). Compiler command  gcc /tmp/SVM-8237896470152817894/PosixDirectives.c -o /tmp/SVM-8237896470152817894/PosixDirectives output included error: /tmp/SVM-8237896470152817894/PosixDirectives.c:60:18: fatal error: zlib.h: No such file or directory
    C file contents around line 60:
    /tmp/SVM-8237896470152817894/PosixDirectives.c:59: #include <unistd.h>
    /tmp/SVM-8237896470152817894/PosixDirectives.c:60: #include <zlib.h>
    /tmp/SVM-8237896470152817894/PosixDirectives.c:61: #include <arpa/inet.h>
Error: Processing image build request failed

My environment:

$ java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-12)
GraalVM 1.0.0-rc1 (build 25.71-b01-internal-jvmci-0.42, mixed mode)
$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
bug native-image

Most helpful comment

Confirmed: adding libz-dev resolved the issue.

All 8 comments

You need to have zlib.h header file installed on your system.
Running

sudo apt-get install libz-dev

should fix your problem.

Can you tell me a little more about that? Is that something I would normally have installed in Debian? Are there any other prerequisites to using Graal? I feel any/all of those should be listed on the Install page.

Generally, if you set up your Linux distro to have all the packages for _general software development_ installed (this is called slightly different in each distro) you should not have problems building native images.

Specifically if you have

  • libc headers + libz header
  • gcc toolchain

installed, image building should work fine.

Thanks for the report @cfsilence. Very much agree that this should be in the description on the website (and probably also the error message).

Confirmed: adding libz-dev resolved the issue.

i got the same error but on windows platform
os-windows 10 64-bit
jdk-11
graalvm-20.2.0

can anyone help me out

Can you post your whole environment? That will make it easier to debug what went wrong.
You can also use our slack channels:

https://www.graalvm.org/community/

@pejovica is PoC for Windows.

Was this page helpful?
0 / 5 - 0 ratings