oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.39k stars 1.64k forks source link

LNK2001: unresolved external symbol Java_sun_reflect_Reflection_getCallerClass Windows 7, GraalVM 19.2.01, native-image #1809

Open gmuecke opened 5 years ago

gmuecke commented 5 years ago

I'm trying to compile Vertx webservice into a native image on Windows 7, using the native-image-maven-plugin, unfortunately I get a link error in the end:

Creating library D:\...\myservice.lib and object D:\...\myservice.exp
myservice.obj : error LNK2001: unresolved external symbol Java_sun_reflect_Reflection_getCallerClass
D:\...\myservice.exe : fatal error LNK1120: 1 unresolved externals

Using:

I'm not sure if this is a bug or if I'm missing something

Maven plugin config

<plugin>
    <groupId>com.oracle.substratevm</groupId>
    <artifactId>native-image-maven-plugin</artifactId>
    <version>19.2.0.1</version>
    <configuration>
        <imageName>myservice</imageName>
        <mainClass>myservice.Launcher</mainClass>
        <buildArgs>
            -H:+ReportUnsupportedElementsAtRuntime
            -H:+ReportExceptionStackTraces
            -H:IncludeResources=.*
            --initialize-at-build-time=io.netty
            --initialize-at-build-time=io.vertx
            --initialize-at-build-time=ch.qos.logback
            --initialize-at-build-time=org.slf4j
            --initialize-at-build-time=com.fasterxml.jackson
            --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder
            --initialize-at-run-time=io.vertx.core.net.impl.transport.EpollTransport
            --initialize-at-run-time=io.vertx.core.net.impl.transport.KQueueTransport
            --allow-incomplete-classpath
        </buildArgs>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>native-image</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

The full logoutput:

[INFO] ImageClasspath: D:\mvn-repository\io\vertx\vertx-core\3.8.2\vertx-core-3.8.2.jar;D:\mvn-repository\io\netty\netty-common\4.1.39.Final\netty-common-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-buffer\4.1.39.Final\netty-buffer-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-transport\4.1.39.Final\netty-transport-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-handler\4.1.39.Final\netty-handler-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-codec\4.1.39.Final\netty-codec-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-handler-proxy\4.1.39.Final\netty-handler-proxy-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-codec-socks\4.1.39.Final\netty-codec-socks-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-codec-http\4.1.39.Final\netty-codec-http-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-codec-http2\4.1.39.Final\netty-codec-http2-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-resolver\4.1.39.Final\netty-resolver-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-resolver-dns\4.1.39.Final\netty-resolver-dns-4.1.39.Final.jar;D:\mvn-repository\io\netty\netty-codec-dns\4.1.39.Final\netty-codec-dns-4.1.39.Final.jar;D:\mvn-repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\mvn-repository\com\fasterxml\jackson\core\jackson-databind\2.9.9.1\jackson-databind-2.9.9.1.jar;D:\mvn-repository\com\fasterxml\jackson\core\jackson-annotations\2.9.9\jackson-annotations-2.9.9.jar;D:\mvn-repository\io\vertx\vertx-web\3.8.2\vertx-web-3.8.2.jar;D:\mvn-repository\io\vertx\vertx-web-common\3.8.2\vertx-web-common-3.8.2.jar;D:\mvn-repository\io\vertx\vertx-auth-common\3.8.2\vertx-auth-common-3.8.2.jar;D:\mvn-repository\io\vertx\vertx-bridge-common\3.8.2\vertx-bridge-common-3.8.2.jar;D:\mvn-repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\mvn-repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\mvn-repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\...\myservice\target\myservice-2.14-SNAPSHOT.jar
[INFO] BuildArgs: [-H:+ReportUnsupportedElementsAtRuntime, -H:+ReportExceptionStackTraces, -H:IncludeResources=.*, --initialize-at-build-time=io.netty, --initialize-at-build-time=io.vertx, --initialize-at-build-time=ch.qos.logback, --initialize-at-build-time=org.slf4j, --initialize-at-build-time=com.fasterxml.jackson, --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder, --initialize-at-run-time=io.vertx.core.net.impl.transport.EpollTransport, --initialize-at-run-time=io.vertx.core.net.impl.transport.KQueueTransport, --allow-incomplete-classpath, -H:Class=myservice.Launcher, -H:Name=myservice]
[myservice:6720]    classlist:  17,223.27 ms
[myservice:6720]        (cap):  18,036.98 ms
[myservice:6720]        setup:  20,894.51 ms
[myservice:6720]   (typeflow):  19,883.13 ms
[myservice:6720]    (objects):  13,448.32 ms
[myservice:6720]   (features):   5,410.26 ms
[myservice:6720]     analysis:  39,582.17 ms
[myservice:6720]     (clinit):     579.70 ms
[myservice:6720]     universe:   1,692.62 ms
[myservice:6720]      (parse):   1,838.96 ms
[myservice:6720]     (inline):   3,261.47 ms
[myservice:6720]    (compile):  14,878.63 ms
[myservice:6720]      compile:  21,855.85 ms
[myservice:6720]        image:  23,997.61 ms
[myservice:6720]        write:   8,582.26 ms
Fatal error: java.lang.RuntimeException: java.lang.RuntimeException: host C compiler or linker does not seem to work: java.lang.RuntimeException: returned 2

Running command: CL /MD /Zi /PDBSTRIPPED /FeD:\...\myservice\target\myservice.exe C:\Users\dc-mug\AppData\Local\Temp\SVM-1870323225520363488\myservice.obj D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES /LIBPATH:D:\tools\graalvm-ce-19.2.1\jre\lib /LIBPATH:D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64 advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib

Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/PDBSTRIPPED'
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug 
/out:D:\...\myservice\target\myservice.exe 
/INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES 
/LIBPATH:D:\tools\graalvm-ce-19.2.1\jre\lib 
/LIBPATH:D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64 
advapi32.lib 
ws2_32.lib 
secur32.lib 
iphlpapi.lib 
C:\Users\dc-mug\AppData\Local\Temp\SVM-1870323225520363488\myservice.obj 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib 
   Creating library D:\...\myservice\target\myservice.lib and object D:\...\myservice\target\myservice.exp
myservice.obj : error LNK2001: unresolved external symbol Java_sun_reflect_Reflection_getCallerClass
D:\...\myservice\target\myservice.exe : fatal error LNK1120: 1 unresolved externals

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
    at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:461)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:310)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:448)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:113)
Caused by: java.lang.RuntimeException: host C compiler or linker does not seem to work: java.lang.RuntimeException: returned 2

Running command: CL /MD /Zi /PDBSTRIPPED /FeD:\...\myservice\target\myservice.exe C:\Users\dc-mug\AppData\Local\Temp\SVM-1870323225520363488\myservice.obj D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib /link /INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES /LIBPATH:D:\tools\graalvm-ce-19.2.1\jre\lib /LIBPATH:D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64 advapi32.lib ws2_32.lib secur32.lib iphlpapi.lib

Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/PDBSTRIPPED'
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug 
/out:D:\...\myservice\target\myservice.exe 
/INCREMENTAL:NO /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:OLDNAMES 
/LIBPATH:D:\tools\graalvm-ce-19.2.1\jre\lib 
/LIBPATH:D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64 
advapi32.lib 
ws2_32.lib 
secur32.lib 
iphlpapi.lib 
C:\Users\dc-mug\AppData\Local\Temp\SVM-1870323225520363488\myservice.obj 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\ffi.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\nio.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\java.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\net.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\libchelper.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\strictmath.lib 
D:\tools\graalvm-ce-19.2.1\jre\lib\zip.lib 
D:\...\myservice\target\native-image-maven-plugin\19.2.0.1\windows-amd64\jvm.lib 
   Creating library D:\...\myservice\target\myservice.lib and object D:\...\myservice\target\myservice.exp
myservice.obj : error LNK2001: unresolved external symbol Java_sun_reflect_Reflection_getCallerClass
D:\...\myservice\target\myservice.exe : fatal error LNK1120: 1 unresolved externals

    at com.oracle.svm.hosted.image.NativeBootImageViaCC.write(NativeBootImageViaCC.java:350)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:657)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
    at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Wooyme commented 4 years ago

I faced similar trouble before. My solution is doing the link by myself and adding argument /FORCE:UNRESOLVED so that the linker will ignore the unresolved externals. You can find the detail in the bottom of https://github.com/Wooyme/jfx-native-image-demo/blob/master/README.md

gmuecke commented 4 years ago

@Wooyme Is there a way to add that flag to the native-image maven plugin?

olpaw commented 4 years ago

@pejovica it seems on Windows we do not respect -H:NativeLinkerOption which would be required to allow users to add custom linker flags on Windows.