Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xCyborg · Dec 01, 2019 at 04:14 PM · c#pluginsil2cppc# dll

Include C/C++ source files as plugins in IL2CPP

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?

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);


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by JoshPeterson · Dec 03, 2019 at 11:50 AM

See the documentation here: https://docs.unity3d.com/2019.3/Documentation/Manual/WindowsPlayerCPlusPlusSourceCodePluginsForIL2CPP.html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 03, 2019 at 12:50 PM 0
Share

Right. It does work just as with normal pre-compiled DLL plugins. He just forgot the extern "C" (either as block or local for the method) to ensure C name encoding and not C++ name mangling.


Also keep in $$anonymous$$d that different platforms might have different calling conventions. Though I guess if the file is just included in the compilation process it would use the correct one.


However I guess that testing plugin code inside the editor would not work for such "plugins" since the code is not compiled so it can not be tested inside the editor. The IL2CPP compiler only runs when you create a build. Testing inside the editor is always done through mono.


Finally I can understand that keeping the source files of plugins has some advantages, though it might come with several downsides. I don't know how the IL2CPP backend actually compiles the final native executable, but we know that the C++ compiler is rather slow if you have a lot of native plugin code. That means it could ramp up your building time which actually makes testing much slower.

avatar image xCyborg Bunny83 · Dec 04, 2019 at 09:35 PM 0
Share

Extern "C" is for C++ not C, but anyway even with that I still get that error.

Failed running C:\Program Files\Unity 2020.1.0a12\Editor\Data\il2cpp/build/deploy/net471/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityaot" --compile-cpp --libil2cpp-static --platform="WindowsDesktop" --architecture="x86" --configuration="Release" --outputpath="C:\Users\HP\Documents\Unity Projects\C11\Temp/StagingArea/Data\Native\GameAssembly.dll" --cachedirectory="C:\Users\HP\Documents\Unity Projects\C11\Assets..\Library/il2cpp_cache" --incremental-g-c-time-slice=3 --profiler-report --map-file-parser="C:/Program Files/Unity 2020.1.0a12/Editor/Data/Tools/$$anonymous$$apFileParser/$$anonymous$$apFileParser.exe" --directory="C:/Users/HP/Documents/Unity Projects/C11/Temp/StagingArea/Data/$$anonymous$$anaged" --generatedcppdir="C:/Users/HP/Documents/Unity Projects/C11/Temp/StagingArea/Data/il2cppOutput"

stdout: Building GameAssembly.dll with $$anonymous$$svcDesktopToolChain $$anonymous$$svc Install Version: 15.0 $$anonymous$$svc Install SD$$anonymous$$ Directory: C:\Program Files (x86)\Windows $$anonymous$$its\10 $$anonymous$$svc Linker Path: C:\Program Files (x86)\$$anonymous$$icrosoft Visual Studio\2019\Community\VC\Tools\$$anonymous$$SVC\14.23.28105\bin\HostX64\x86\link.exe $$anonymous$$svc Compiler Path: C:\Program Files (x86)\$$anonymous$$icrosoft Visual Studio\2019\Community\VC\Tools\$$anonymous$$SVC\14.23.28105\bin\HostX64\x86\cl.exe

 Output directory: C:\Users\HP\Documents\Unity Projects\C11\Temp\StagingArea\Data\Native
 Cache directory: C:\Users\HP\Documents\Unity Projects\C11\Library\il2cpp_cache

il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: plug.c C:\Users\HP\Documents\Unity Projects\C11\Temp\StagingArea\Data\il2cppOutput\plug.c(4): error C2059: syntax error: 'string'

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

116 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Multiple plugins with the same name 0 Answers

How to read a file from OneDrive folder in HoloLens app 0 Answers

How to read uploaded WebGL binary files? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges