When I run my html5 game, the gdnative library failed to load because file is not found

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robotex

I compiled my GDN library for javascript target using emscripten and connected it to the game. But after export into HTML5, my game can’t find the library file. Looks like it missing and not exported. How to add it to game package?

The same situation if I just load game in browser by Run HTML5 button from Editor.

What is wrong?

The project files: godot_project.zip - Google Drive

index.js:362 ERROR: Can't open dynamic library: bin/javascript64/TinyRTSGDNative.wasm. Error: Could not load dynamic lib: TinyRTSGDNative.wasm
index.js:362 Error: TinyRTSGDNative.wasm: file not found, and synchronous loading of external files is not available
index.js:362    at: open_dynamic_library (platform/javascript/os_javascript.cpp:1054) - Condition "!p_library_handle" is true. Returned: ERR_CANT_OPEN
index.js:362 ERROR: No valid library handle, can't get symbol from GDNative object
index.js:362    at: get_symbol (modules/gdnative/gdnative.cpp:510) - No valid library handle, can't get symbol from GDNative object
index.js:362 ERROR: No nativescript_init in "res://bin/javascript64/TinyRTSGDNative.wasm" found
index.js:362    at: init_library (modules/gdnative/nativescript/nativescript.cpp:1510) - No nativescript_init in "res://bin/javascript64/TinyRTSGDNative.wasm" found
:bust_in_silhouette: Reply From: Ertain

Was the file “TinyRTSGDNative.wasm” added to the project, or was it generated by the engine? If it was added, the file will have to be manually added when the game is exported.

When exporting the game (by going to the editor and selecting ProjectExport…, then selecting the export preset), a file can be added to the game package. In the Export dialog, click on the Resources tab and then enter the file that needs to be exported. In this case, it would be “TinyRTSGDNative.wasm” (without the quotes).

Optional files to export

That should export the game along with the desired file. If entering just the file name doesn’t work, it may also need the path to the file, i.e. bin/javascript64/TinyRTSGDNative.wasm.

No, it didn’t help. And what is about the HTML5 Run in browser button at Editor. How the export settings related to it?

Robotex | 2022-05-02 08:49

:bust_in_silhouette: Reply From: Robotex

I found what was wrong. Problem was caused by two factors:

  1. using library resource as subresource instead of gdnlib file.
    I created gdnlib file with path to libraries for different platforms
    and included it to gdns file instead of subresource. It helped.
  2. the latest emscripten version on the windows.
    I used 3.1.9 before and then downgraded to 2.0.12. It helped.