I’ve built a simple static lib from very simple .c source file into a .bc file but I can’t never call the function from c#.
My .c file is:
#include <stdio.h>
int AddNumbers (int x, int y)
{
return x + y;
}
and then on c#
[DllImport("__Internal")]
private static extern int AddNumbers(int x, int y);
To compile the .c file I’ve created a MakeFile with c flags set to ‘-emit-llvm’ using CMake and compiled it with Emscripten
./emmake make
It generates a .a lib file that I’ve renamed to .bc and moved into Unity Assets and marked as a WebGL plugin.
When i call the AddNumber method I always get this error:
An error occurred running the Unity content on this page. See your browser's JavaScript console for more info. The error was:
abort(-1) at jsStackTrace (WebGLPlugin.js:1:19708)
stackTrace (WebGLPlugin.js:1:19882)
abort (WebGLPlugin.js:3:32695)
_AddNumbers (WebGLPlugin.js:1:186759)
Pwo (WebGLPlugin.asm.js:10:844115)
N_l (WebGLPlugin.asm.js:4:87306)
If I just drop the .c file inside Unity Assets it runs without a problem.
The reason I want to create the .bc file is because I want to compile a much larger code base.
I’ve followed from this thread
Thanks