Home Game Development Godot 3.5: Web Build using custom GDNative C++ Library does not work due to `dlopen` error and failed linking

Godot 3.5: Web Build using custom GDNative C++ Library does not work due to `dlopen` error and failed linking

0
Godot 3.5: Web Build using custom GDNative C++ Library does not work due to `dlopen` error and failed linking

[ad_1]

The Problem

Currently I am trying to get the official GDNative C++ example for Godot 3.5, which can be found here working in the Web Export context. So far, I managed to export to X11.64 without any troubles and managed to set up the creation pipeline for the Web Assembly (see section “Web Assembly Creation Process” below), which now produces a valid output without any error messages. However, as soon as I try to run the game in any browser, it stops loading and displays the following error message:

Aborted(To use dlopen, you need enable dynamic linking, 
see https://github.com/emscripten-core/emscripten/wiki/Linking)

This link only contains a link to the new documentation of emscripten, which is used to create the Web Assembly file, and is at the time of writing located at https://emscripten.org/docs/compiling/Dynamic-Linking.html.

Final File Structure

ROOT/
  ├─godot-project-src/
  |   └─lib/
  |      ├─wasm/
  |      |   └─libsimple.wasm
  |      ├─SimpleLibrary.gdnlib
  |      └─SimpleLibrary.gdns
  └─SimpleLibrary/
      ├─godot-cpp/
      |    ├─bin/
      |    |  └─libgodot-cpp.javascript.release.wasm.a
      |    ├─include/
      |    |   ├─core/
      |    |   └─gen/
      |    └─godot-headers/
      ├─bin/
      |  └─libsimple.wasm
      └─src/
         └─init.cpp

Web Assembly Creation and Export Process

At the beginning of the project (only necessary once):

  1. Initialize SimpleLibrary directory with godot-cpp and godot-headers.
  2. Create the release JavaScript Godot Binding via
    scons platform=javascript generate_bindings=yes target=release,
    which creates the archive SimpleLibrary/godot-cpp/bin/libgodot-cpp.javascript.release.wasm.a.
  3. Create GDNative Import Files in the Godot Project Directory.
     godot-project-src/lib/SimpleLibrary.gdnlib
     godot-project-src/lib/SimpleLibrary.gdns
    

After each change:

  1. Create the new Web Assembly Library
     cd SimpleLibrary
     emcc -o bin/libsimple.wasm -g -O3 -sSIDE_MODULE=1 src/init.cpp godot-cpp/bin/libgodot-cpp.javascript.release.wasm.a -Igodot-cpp/include -Igodot-cpp/include/core -Igodot-cpp/include/gen -Igodot-cpp/godot-headers
    
  2. Copy the newly created library to the correct location in the Godot Project Folder
   cp bin/libsimple.wasm ../godot-project-src/lib/wasm
  1. Update (if necessary) the GDNative Import Files in the Godot Project Directory.
     godot-project-src/lib/SimpleLibrary.gdnlib
     godot-project-src/lib/SimpleLibrary.gdns
    

Web Export

Just selecting the HTML Export Template via the Godot Editor, choosing the Export Folder and let Godot do its thing.

Questions

  1. Did I miss some necessary settings during the Web Assembly creation? I already had to change some compiler flags for emccand add include directories compared to the original example to get it even to compile. I also experimented with the optimization flags, the deprecated -shared flag, -sDYNAMIC_EXECUTION, -sMAIN_MODULE, but no changes.
  2. Do I have to create a custom HTML Export Template for this to work properly? According to the GDNative Documentation, if
   godot-project-src/lib/SimpleLibrary.gdnlib
   godot-project-src/lib/SimpleLibrary.gdns

are created properly, this should not be necessary.

  1. Is the GDNative C++ Web Export at all possible? During my research, I only found very vague documentation, a lot of (not really related) github issues and more questions than answers.

[ad_2]