Search Unity

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

Discussion in 'Scripting' started by xCyborg, Dec 1, 2019.

  1. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    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:

    Code (csharp):
    1. #include <math.h>
    2. #define EXPORT __declspec(dllexport)
    3.  
    4. /* Power function*/
    5. EXPORT int power1(int n, int p)
    6. {
    7.    int r = pow(n, p);
    8.    return r;
    9. }
    C#
    Code (csharp):
    1.  
    2. [DllImport("__Internal", EntryPoint ="power1")] static extern int power1(int n, int p);
    3.  
     
  2. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    540
  3. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    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?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Editor itself is Mono only. Those C/C++ files can only be used in player, not in Editor.
     
  5. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    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 .