- Home /
Using Native C++ dll in Unity
Hi, I am new to Unity and C++ and C#. I have a UWP component (C++) I want to use in my Unity project through C# scripts. I am thinking the best way to do this is by taking the UWP component and building a dll from Visual Studio. To practice I wrote and generated a managed DLL following a tutorial and imported and used it in Unity. However, the code I want to access produced a native dll and I am unsure how to use that in Unity. So either how do I convert a native dll to a managed dll, or how do I use a native dll in Unity?
Thanks.
It's a long time ago sinse I tried to do this, so I'm not be able to help you with specific questions... But dit you read the manual about this? Seems a bit old sinse it still mentions javascript, but the C# code example should still work in te same way.
Answer by ivan866 · Jun 05, 2019 at 10:59 AM
Use SWIG
wrapper. But beware of cpp method name mangling.
You need to compile the code with-Wl,--kill-at
compiler flags,CFLAGS="-O -arch i386" CXXFLAGS="-O -arch i386" LDFLAGS="-arch i386" --disable-dependency-tracking
compiler flags,
and try extern "C" and Calling Convention [ cdecl
, stdcall
] directives.