Search Unity

WebGL with C++ static library

Discussion in 'Web' started by peter06, Apr 7, 2021.

  1. peter06

    peter06

    Joined:
    Apr 7, 2021
    Posts:
    2
    Is it possible to use C++ static library for Unity WebGL?

    First, I generate the llvm bitcode by using "clang -emit-llvm -o libhello_webgl.bc -c hello_webgl.cpp"
    Second, I drop this libhello_webgl.bc in the floder "Assets"--"Plugins"--"WebGL"
    Third, I create the C# script to import this function like this:
    [DllImport("__Internal")]
    private static extern int sum_dll_webgl(int x, int y);

    Unfortunately, the error message is "libhello_webgl.bc is not valid according to llvm-nm, can not link"

    If I use the C++ source code instead of this static library, it works.

    Thank you for your suggestion.
     
  2. peter06

    peter06

    Joined:
    Apr 7, 2021
    Posts:
    2
    This forum is dead?
    I solved this problem, the reason is the version of emscripten, the default version in Unity is very old.
     
    De-Panther likes this.
  3. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Yes, you should use emscripten to build the static lib.
    And it'll be helpful if you'll write here how you solved it...
    emscripten version? build command line?
    Thanks