Search Unity

Question WebGL + Native Plugin + External Library => Never builds.

Discussion in 'Web' started by Gobla, Jan 7, 2022.

  1. Gobla

    Gobla

    Joined:
    May 28, 2012
    Posts:
    354
    I've been looking into having a WebGL build of a specific plugin I've made which uses 3 "external" libraries.

    What have I done so far:
    • [Successfully] Build an "empty" project using Webassembly as a test.
    • [Successfully] Build an "empty" project using Webassembly and a dummy native plugin that uses no external libraries which works as intended.
    • [Successfully] I've written the plugin and have the 3 external libraries stripped and included by source (thus no .lib/.dll files linked).
    • [Successfully] I've compiled the plugin using visual studio to test this in the editor and standalone (windows). This works as intended.
    • [Fails] I've tried to build the plugin by setting a WebGL build.
      • This process just results in having a progress bar often noting something like C_WebGL_wasm Library/Bee/artifacts/WebGL/il2cpp/master_WebGL_wasm/<somefile>.
      • CPU % is to 0 after a few seconds to a few mins.
      • Let it build overnight (10 hours), no result.
      • Clean builds don't resolve anything
      • Closing Unity, Removing the Library folder, Re-opening and trying to build doesn't work.
      • Adding/removing include paths and libraries to the il2cpp builder and even placing the external libraries in "C:\Program Files\Unity\Hub\Editor\2021.2.7f1\Editor\Data\il2cpp\external\baselib\Platforms\WebGL\Include"
        • Removing the libraries results in errors of files not found (as expected).
        • Occasionally something seems to compile and I get an error of not using the "-frtti" flag which I added. However, this still results in (no idea how to consistently replicate this, even a clean setup won't always result in this error).
      • Inspect with process explorer, no activity.
    So I am kinda stuck here. At one point I did manage to build the project to the point I got a symbol not found error somewhere in the plugin itself. I've shown steps to replicate this here: https://forum.unity.com/threads/web...al-library-never-builds.1221489/#post-7788324

    Any help/tips/suggestions on how to make this work?

    Thanks in advance!

    Edit: Not using BitDefender.
     
    Last edited: Jan 7, 2022
  2. Gobla

    Gobla

    Joined:
    May 28, 2012
    Posts:
    354
    I've managed to replicate the steps to get the symbol not found error referring to parts of the actual plugin:

      • Clean project
      • Put the extra libraries in "C:\Program Files\Unity\Hub\Editor\2021.2.7f1\Editor\Data\il2cpp\external\baselib\Platforms\WebGL\Include"
      • Disable the plugin via the inspector
      • Remove/comment the c# code referring to the plugin
      • Remove all compiler flags
      • Build (Succes)
      • Enable the plugin via the inspector
      • Build (It compiles additional files but it fails based upon the missing "-frtti" flag)
      • Add the compiler flags '--compiler-flags="-frtti"'
      • Build (Succes) ==> Step 2 build might be skipped but I have not tested this yet
      • Add/uncomment the c# code referring to the plugin
      • Build (Fails)
        • Error: Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: _ZN12registration36update_normals_for_altered_positionsERKN5Eigen6MatrixIfLin1ELi3ELi0ELin1ELi3EEERKNS1_IiLin1ELi3ELi0ELin1ELi3EEERS2_ (referenced by top-level compiled C/C++ code)

      Edit: Finally managed a build using this weird build order by manually adding all the .cpp / .cc files in the project plugin file by direct reference rather than using #include <Library>

      This could result in lots of files. Are there any suggestions on how to make the #include <Library> function work?
     
    Last edited: Jan 7, 2022
    MartinChungCY likes this.
  3. chrisdjali-wrld3d

    chrisdjali-wrld3d

    Joined:
    Apr 23, 2021
    Posts:
    3
    In C/C++, you don't include a library, you include a header. Sometimes a library will be just a header/several headers, but usually, it'll have source files, too. Basically, the header just declares which functions exist, and the source files are where the implementation is. You'll need to either add these source files to your plugin, or build them as their own static library (a
    .bc
    LLVM bitcode file for Unity 2020 and older, or a WASM
    .a
    archive for 2021) and include that as another plugin Unity will link into the build.
     
  4. Gobla

    Gobla

    Joined:
    May 28, 2012
    Posts:
    354
    I will look into building the libraries in a static fashion and include these. I will report this afterwards.
     
    MartinChungCY likes this.
  5. AZHARKHEMTA

    AZHARKHEMTA

    Joined:
    Nov 22, 2021
    Posts:
    2
    i am facing these issues when i make a build
    Any solution please
    Error
    Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: ShowMessage (referenced by top-level compiled C/C++ code)

    Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: checkMetamask (referenced by top-level compiled C/C++ code)
    Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: connectToMetamask (referenced by top-level compiled C/C++ code)
     
  6. Soulside

    Soulside

    Joined:
    Nov 1, 2018
    Posts:
    30
    Hey @Gobla, have you figured out how to build the static libraries for WebGL?