You can compile libraries with Emscripten and use the libraries in Unity. It can be more beneficial to call functions from libraries that encapsulate C++ code rather than C++ code directly from the plug-in directory. The benefits include:
To compile a static library that you can use as a Unity plug-in:
You must download the Emscripten SDK that matches your version of Unity.
To find the appropriate version of Emscripten for your Unity version, refer to Web native plug-ins for Emscripten.
For download links and more information about how to install the Emscripten SDK, refer to Download and install (Emscripten).
Emscripten works as a replacement for the gcc or clang compiler. If you have existing C/C++ code, you need to make the following changes in your C++ project:
For more information, refer to the Emscripten documentation on Compiling and Running Projects.
You might need to add compiler options to your C/C++ project if your Unity project uses the following Player settings (menu: Edit > Project Settings > Player).
For the required Emscripten build flags corresponding to these settings, refer to the Emscripten build flags table in Web native plug-ins for Emscripten.
Compile your static library files and then import your files into your Unity project in the Assets/Plugins folder.
Note: If you don’t have a Plugins folder, you need to create your own.
You can call your static library functions from your Unity C# scripts. The way to call the functions is the same as if you call a C or C++ function from C# scripts. For an example, refer to Call C/C++/C# functions from Unity C# scripts.