Including C/C++ source files as plugins in IL2CPP back-end.

I’ve been trying to write simple functions in C and use IL2CPP to include them in my plugin directory directly without building DLLs because I find it more straightforward as well as less costly P/Invoke wise as well as maybe not needing to restart Unity each time I make a change.

But when I target IL2CPP scripting back-end w/ standalone target I always get this error in the editor in play mode: EntryPointNotFoundException And when I build I get /il2cpp.exe did not run properly!

I have VS2019 w/ C++ workload and Windows 10 SDK.

Anyone knows how to use native source files and IL2CPP in Unity? Somethong wrong I’m doing? The docs weren’t much help.

Sample code:

#include <math.h>
#define EXPORT __declspec(dllexport)

/* Power function*/
EXPORT int power1(int n, int p)
{
   int r = pow(n, p);
   return r;
}

C#

[DllImport("__Internal", EntryPoint ="power1")] static extern int power1(int n, int p);

As far as I know it will only work with C++ files, you could try to rename your .c file to .cpp the code should still be valid.

Maybe this link will help https://docs.unity3d.com/2019.1/Documentation/Manual/WindowsPlayerCPlusPlusSourceCodePluginsForIL2CPP.html

I tried that as well but it didn’t work, although Unity seems to recognize .c files as plugins in the inspector as well.

I did everything I could find on the documentation but nothing works, anybody used it before?

Editor itself is Mono only. Those C/C++ files can only be used in player, not in Editor.

I suspected that, but even when I build a player with IL2CPP it still doesn’t build successfully at all whenever I just include native files.
I filed a bug report actually: case .