What is the correct way to use .a static libraries in webgl? getting runtime errors

Hi, i need someones help. The problem is:
I am trying to use .a library in my project. it is SkiaSharp, that works ok on mac, android, ios, windows. And it has wasm support, but I cant make it work in unity web builds. When I use C# wrapper I get errors:

First one:
test.loader.js:1 To use dlopen, you need to use Emscripten’s linking support, see Linking · emscripten-core/emscripten Wiki · GitHub

and

test.framework.js.gz:2 DllNotFoundException: Unable to load DLL ‘libSkiaSharp’: The specified module could not be found.
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888 () [0x00000] in <00000000000000000000000000000000>:0
at SkiaSharp.SKImageInfo…cctor () [0x00000] in <00000000000000000000000000000000>:0
at SkiaSharp.SKBitmap…ctor (System.Int32 width, System.Int32 height, System.Boolean isOpaque) [0x00000] in <00000000000000000000000000000000>:0
at Test.Start () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for ‘SkiaSharp.SKImageInfo’ threw an exception.
at SkiaSharp.SKBitmap…ctor (System.Int32 width, System.Int32 height, System.Boolean isOpaque) [0x00000] in <00000000000000000000000000000000>:0
at Test.Start () [0x00000] in <00000000000000000000000000000000>:0

But I have libSkiaSgarp.a library built for wasm, and it works for Uno Platform, but does not for unity.
Maybe I am doing something wrong?

having the same issue here

As shown in the manual, in Unity WebGL you need to use [DllImport(“__Internal”)] and not the lib/file name.

Thank you, I tried to use __Internal, but now i get

“wasm-ld: error: duplicate symbol” errors :frowning:

Building Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js failed with output:
wasm-ld: error: duplicate symbol: jsimd_can_rgb_ycc
>>> defined in /var/folders/18/99jndmds6px_w52xph7yfc_h0000gn/T/tmpo_khbkvaWebGLSupport_ImageConversionModule_Dynamic.a(External_libjpeg-turbo_src_0_j00uw.o)
>>> defined in Assets/Scenes/Plugins/WebGL/libSkiaSharp.a(libjpeg.jsimd_none.o)

I think that the problem is duplicate of same library (libjpeg) inside libSkiaSharp.a and Unity3d, but I cant find the way how to solve it

I fixed duplicate errors, the solution was to rebuild libjpeg, libpng and freetype with rename of some of their methods. Now I’ve got new pack of errors

First I had problems with libjpg and libpng, conflicting names. So I Created some regex functions and remaned them everywhere in skia (jsimd functions and etc)

Then I had problems on Linking:
Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js: undefined symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE17__assign_externalEPKcm (referenced by top-level compiled C/C++ code)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPlayerWindow.cs:179)

The reason was my emscripten version (2.0.32),So I downgraded to 2.0.19 (same as Unity 2021.2) and installed Ubuntu 2.0.4 (cause 2.0.19 does not exist for my mac)

Now it compiles. But I get runtime errors:

at http://localhost:49782/Build/skia.wasm.gz:wasm-function[35775]:0xa659b0
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3667]:0x122e5f
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3668]:0x122f78
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[9093]:0x34de83
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[35429]:0xa3fcfe
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[16989]:0x632db5
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[2786]:0xcab5e
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[16979]:0x63298d
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[20165]:0x782c31
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[26785]:0x923f3b
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3848]:0x13a31c
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[687]:0x25741
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[34354]:0xa2350d
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[26785]:0x923f3b
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3848]:0x13a31c
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[687]:0x25741
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12641]:0x55cc09
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3866]:0x13acb1
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12823]:0x5620be
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3001]:0xe3a28
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[28620]:0x945350
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[27463]:0x92f9a0
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[17433]:0x67009c
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[959]:0x32eb5
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3326]:0x106663
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[25951]:0x8f772c
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[24919]:0x89d6b6
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[23583]:0x7ecc60
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12154]:0x54768f
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12154]:0x5476fe
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[10676]:0x458824
at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21608]:0x7a9d99
at browserIterationFunc (http://localhost:49782/Build/skia.framework.js:2:257698)
at callUserCallback (http://localhost:49782/Build/skia.framework.js:2:131767)
at Object.runIter (http://localhost:49782/Build/skia.framework.js:2:133027)
at Browser_mainLoop_runner (http://localhost:49782/Build/skia.framework.js:2:131302)

I dont know what to do with it yet. but I am surprised to see skia.was.gz here, cause I do not use gz compression in Unity for now. Can it be a bug?

An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.

I found out that it does not fail on development build, and fails on dev build off. I start thinkng there can be a bug. I will investigate this problem and create a reproductable test to make sure

I don’t know what is your use case, but maybe you should try and work with 2 WASM files,
one for unity, one for the external lib.
and just share between them the end result.
It may help you later in case you need large amount of memory

Very interesting idea, I will investigate it too, but first I will try to check if native lib can be called from C# all inside unity without implementing 2 wasm programs

So I made it to work in development build. Now I will try investigate if there is a bug and will provide reproduction project

So development build works, and non development does not. I will start the new thread and prepare the repo with repro