0

I'm trying to build a JavaFx and compile it to native with GluonFX. Recently I needed to add a feature that uses a native C Library. I used org.graalvm.nativeimage for this.

The problem I'm having is that the "Link" step fails because it doesn't find the library I need to use, or that's what I'm think. This is the output of the error:

   Creating library [path to project].lib and object [path to project].exp
[project].obj : error LNK2001: unresolved external symbol tt_init
[project].exe : fatal error LNK1120: 1 unresolved externals

I tried to copy the library in the graalvm libs folder indicated in the Link step, but that doesn't work.

Do you know the configuration I need to add in Maven or the GluonFx plugin to indicate to the plugin to load this library too?

Thanks in advance

Edited:

After suggestions of @JosePereda, bumped the version of gluonfx-maven-plugin to 1.0.13-SNAPSHOT and added the arguments:

<linkerArgs>
   <arg>-l$lib</arg>
   <arg>-L$C:/[path to the library]/ttcmp/ttcmp.lib</arg>
</linkerArgs> 

But now I'm having the given error in the link step after execution of mvn clean gluonfx:build:

NFO] <<< gluonfx-maven-plugin:1.0.13-SNAPSHOT:compile (default-cli) < process-classes @ [project]<<<
[INFO]
[INFO]
[INFO] --- gluonfx-maven-plugin:1.0.13-SNAPSHOT:compile (default-cli) @ [project]---
Mar 07, 2022 9:28:14 AM com.gluonhq.substrate.util.Logger logInfo
INFO: Substrate is tested with the Gluon's GraalVM build which you can find at https://github.com/gluonhq/graal/releases.
While you can still use other GraalVM builds, there is no guarantee that these will work properly with Substrate
[Mon Mar 07 09:28:14 CET 2022][INFO] ==================== COMPILE TASK ====================
             _______  ___      __   __  _______  __    _
            |       ||   |    |  | |  ||       ||  |  | |
[Mon Mar 07 09:28:16 CET 2022][INFO] We will now compile your code for x86_64-microsoft-windows. This may take some time.
            |    ___||   |    |  | |  ||   _   ||   |_| |
            |   | __ |   |    |  |_|  ||  | |  ||       |
            |   ||  ||   |___ |       ||  |_|  ||  _    |
            |   |_| ||       ||       ||       || | |   |
            |_______||_______||_______||_______||_|  |__|

    Access to the latest docs, tips and tricks and more info on
    how to get support? Register your usage of Gluon Substrate now at

    https://gluonhq.com/activate



[Mon Mar 07 09:28:32 CET 2022][INFO] [SUB] Warning: Ignoring server-mode native-image argument --no-server.
[Mon Mar 07 09:29:08 CET 2022][INFO] [SUB] ========================================================================================================================
[Mon Mar 07 09:29:08 CET 2022][INFO] [SUB] GraalVM Native Image: Generating '[project name]'...
[Mon Mar 07 09:29:08 CET 2022][INFO] [SUB] ========================================================================================================================
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB] [1/7] Initializing...                                                                                   (27.0s @ 0.68GB)
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]  Version info: 'GraalVM 22.0.0.2 Java 11 CE'
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]  1 native library: ttcmp
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]  3 user-provided feature(s)
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]   - com.oracle.svm.thirdparty.gson.GsonFeature
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]   - io.micronaut.buffer.netty.NettyFeature
[Mon Mar 07 09:29:19 CET 2022][INFO] [SUB]   - io.micronaut.http.netty.graal.HttpNettyFeature
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB] [2/7] Performing analysis...  [***********]                                                            (214.5s @ 4.79GB)
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB]   20,801 (91.34%) of 22,772 classes reachable
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB]   38,528 (71.80%) of 53,660 fields reachable
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB]  109,527 (63.74%) of 171,826 methods reachable
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB]    1,022 classes, 1,029 fields, and 2,818 methods registered for reflection
[Mon Mar 07 09:32:54 CET 2022][INFO] [SUB]      146 classes,   176 fields, and   210 methods registered for JNI access
[Mon Mar 07 09:33:00 CET 2022][INFO] [SUB] [3/7] Building universe...                                                                               (6.1s @ 6.23GB)
[Mon Mar 07 09:33:06 CET 2022][INFO] [SUB] [4/7] Parsing methods...      [**]                                                                       (4.3s @ 5.29GB)
[Mon Mar 07 09:33:34 CET 2022][INFO] [SUB] [5/7] Inlining methods...     [*****]                                                                   (27.0s @ 2.90GB)
[Mon Mar 07 09:33:34 CET 2022][INFO] [SUB] GC warning: 17.4s spent in 4 GCs during the last stage, taking up 62.29% of the time.
[Mon Mar 07 09:33:34 CET 2022][INFO] [SUB]             Please ensure more than 9.04GB of memory is available for Native Image
[Mon Mar 07 09:33:34 CET 2022][INFO] [SUB]             to reduce GC overhead and improve image build time.
[Mon Mar 07 09:34:28 CET 2022][INFO] [SUB] [6/7] Compiling methods...    [*******]                                                                 (54.7s @ 4.17GB)
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] [7/7] Creating image...
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] ------------------------------------------------------------------------------------------------------------------------
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]                        77.7s (22.1% of total time) in 61 GCs | Peak RSS: 9.04GB | CPU load: 4.87
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] ------------------------------------------------------------------------------------------------------------------------
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] Produced artifacts:
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]  C:[project path].h (header)
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]  C:\[project path]\graal_isolate.h (header)
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]  C:[project path]_dynamic.h (header)
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]  C:\[project path]\graal_isolate_dynamic.h (header)
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB]  C:\[project path]t.build_artifacts.txt
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] ========================================================================================================================
[Mon Mar 07 09:34:43 CET 2022][INFO] [SUB] Finished generating '[project name]' in 5m 50s.
[INFO]
[INFO] --- gluonfx-maven-plugin:1.0.13-SNAPSHOT:link (default-cli) @ [project]---
[Mon Mar 07 09:34:45 CET 2022][INFO] Substrate is tested with the Gluon's GraalVM build which you can find at https://github.com/gluonhq/graal/releases.
While you can still use other GraalVM builds, there is no guarantee that these will work properly with Substrate
[Mon Mar 07 09:34:45 CET 2022][INFO] ==================== LINK TASK ====================
[Mon Mar 07 09:34:45 CET 2022][INFO] Default icon.ico image generated in C:\[project path]\target\gluonfx\x86_64-windows\gensrc\windows\assets.
Consider copying it to C:\[project path]\src\windows before performing any modification
[Mon Mar 07 09:34:47 CET 2022][INFO] [SUB] Microsoft (R) Incremental Linker Version 14.31.31104.0
[Mon Mar 07 09:34:47 CET 2022][INFO] [SUB] Copyright (C) Microsoft Corporation.  All rights reserved.
[Mon Mar 07 09:34:47 CET 2022][INFO] [SUB]
[Mon Mar 07 09:34:47 CET 2022][INFO] [SUB] LINK : warning LNK4044: unrecognized option '/l$lib'; ignored
[Mon Mar 07 09:34:47 CET 2022][INFO] [SUB] LINK : warning LNK4044: unrecognized option '/l$C:/[project path]/src/main/resources/ttcmp/ttcmp.lib'; ignored
[Mon Mar 07 09:34:48 CET 2022][INFO] [SUB]    Creating library C:\[project path].lib and object C:\[project path].exp
[Mon Mar 07 09:34:48 CET 2022][INFO] [SUB] [project].obj : error LNK2001: unresolved external symbol tt_init
[Mon Mar 07 09:34:48 CET 2022][INFO] [SUB] C:\[project path].exe : fatal error LNK1120: 1 unresolved externals
[Mon Mar 07 09:34:48 CET 2022][SEVERE] Process link failed with result: 1120
Check the log files under C:\[project path]\target\gluonfx\x86_64-windows\gvm\log
[INFO] ------------------------------------------------------------------------
And please check https://docs.gluonhq.com/ for more information.
[INFO] BUILD FAILURE
[Mon Mar 07 09:34:48 CET 2022][INFO] Logging process [link] to file: C:\[project path]\target\gluonfx\log\process-link-1646642088313.log
[INFO] ------------------------------------------------------------------------
[Mon Mar 07 09:34:48 CET 2022][SEVERE] Linking failed.
[INFO] Total time:  07:00 min
Check the log files under C:\[project path]\target\gluonfx\x86_64-windows\gvm\log
[INFO] Finished at: 2022-03-07T09:34:48+01:00
And please check https://docs.gluonhq.com/ for more information.
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.gluonhq:gluonfx-maven-plugin:1.0.13-SNAPSHOT:link (default-cli) on project [project]: Linking failed -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  07:08 min
[INFO] Finished at: 2022-03-07T09:34:48+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.gluonhq:gluonfx-maven-plugin:1.0.13-SNAPSHOT:build (default-cli) on project [project]: Error, gluonfx:build failed -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

This is the log in process-link-1646642088313.log:

Output
======
Microsoft (R) Incremental Linker Version 14.31.31104.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : warning LNK4044: unrecognized option '/l$lib'; ignored
LINK : warning LNK4044: unrecognized option '/l$C:/[path to the library]/ttcmp/ttcmp.lib'; ignored
Creating library C:\[path to the project].exp
[project].obj : error LNK2001: unresolved external symbol tt_init
[path to the project].exe : fatal error LNK1120: 1 unresolved externals


Result
======
result: 1120

I'm using:

GraalVM 22.0.0.2
org.graalvm.nativeimage:library-support 22.0.0.2
io.micronaut:micronaut-parent 3.3.4
io.micronaut.build:micronaut-maven-plugin 3.1.1
org.openjfx:javafx-maven-plugin 0.0.8
com.gluonhq:gluonfx-maven-plugin 1.0.13-SNAPSHOT
Visual Studio 2022 Developer Command Prompt v17.1.0
Ikaro
  • 165
  • 1
  • 12
  • 2
    You can add link arguments with `-l$lib-L$path_to_the_lib` starting with GluonFX plugin 1.0.13-SNAPSHOT. You need to include in your pom: `Snapshotshttps://oss.sonatype.org/content/repositories/snapshots/` in order to use it. – José Pereda Mar 01 '22 at 15:40
  • Thanks @JoséPereda . Do you know any other solution for lower versions? I can't use Snapshots versions on my project :'( – Ikaro Mar 02 '22 at 07:42
  • 1
    First: did you try the snapshot and did it work? The plugin will be released eventually, so you'll have to wait for the next release. – José Pereda Mar 02 '22 at 09:54
  • Thanks, I'm changing the necessary things to make it work with the snapshot. Needed to bump my Graalvm version and I'm having this error which I'm trying to solve ```Fatal error: java.lang.NoSuchMethodError: 'org.graalvm.compiler.options.OptionDescriptor org.graalvm.compiler.options.OptionDescriptor.create(java.lang.String, org.graalvm.compiler.options.OptionType, java.lang.Class, java.lang.String, java.lang.Class, java.lang.String, org.graalvm.compiler.options.OptionKey, boolean)'``` – Ikaro Mar 02 '22 at 10:08
  • btw @JoséPereda the url to the snapshot repository returns "Directory listing forbidden" – Ikaro Mar 02 '22 at 12:29
  • Yes, but the plugin URL can be listed: https://oss.sonatype.org/content/repositories/snapshots/com/gluonhq/gluonfx-maven-plugin/1.0.13-SNAPSHOT/ – José Pereda Mar 02 '22 at 12:41
  • @JoséPereda I keep having the same error ```java.lang.NoSuchMethodError: 'org.graalvm.compiler.options.OptionDescriptor org.graalvm.compiler.options.OptionDescriptor.create``` Using: Graalvm 22.0.0.2 Micronaut: 3.1.4 GluonFx: 1.0.13-SNAPSHOT (Also with 1.0.12 & 1.0.11) – Ikaro Mar 02 '22 at 15:13
  • 1
    Edit your question and post details of what you are doing. What dependencies you have and a more detailed stacktrace. Impossible to say why it fails for you otherwise. – José Pereda Mar 02 '22 at 15:28
  • I have followed the steps you asked me to update to 1.0.13-SNAPSHOT and I have edited the post with the error logs and the versions I am using. thanks for the remark – Ikaro Mar 07 '22 at 08:50
  • Oh, I assumed that you would replace `$lib` with your real library name, and `$path_to_the_lib` with the path to such file... – José Pereda Mar 07 '22 at 09:04
  • lol :) I replaced the path, just hide it for privacy. But I, haven't replaced the lib thinking it was a regular expression or something like that. I'm trying again now. Thanks ! – Ikaro Mar 07 '22 at 09:31
  • 1
    See the current `link` command in your log, it will give you a hint of the libs that are added (with `-l` prefix), and the paths (with `-L`) used to find them. – José Pereda Mar 07 '22 at 09:33
  • @JoséPereda I couldn't make it in that way :(. But follow your tips and added this config using the commands in the link logs `-WHOLEARCHIVE:${ttcmp.library.name}-LIBPATH:${ttcmp.library.path}` And worked! – Ikaro Mar 07 '22 at 13:16
  • 1
    Great, yeah, linking libraries is not straightforward, and there are several use cases in the link command. – José Pereda Mar 07 '22 at 14:11

0 Answers0