Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by funx · Oct 11, 2020 at 01:22 PM · il2cppcompilernative pluginnative

How to enable '-fdeclspec' or '-fms-extensions' compiler options to compile C++ source code in project?

I'm trying to have C++ source code in my project compiled when I build it instead of having a library instead to avoid the performance costs of P/Invoke.

Following the instructions here: https://docs.unity3d.com/2019.3/Documentation/Manual/macOSPlayerCPlusPlusSourceCodePluginsForIL2CPP.html

I've got the C++ code in Assets/Plugins/Mac/x86_64/NativeFunctions.cpp and the import settings set to Standalone/Mac OS X x64.

When I try to build and run I get this error (and warning):

 [ERROR] FATAL UNHANDLED EXCEPTION: Unity.IL2CPP.Building.BuilderFailedException: /Users/....../project/Temp/StagingArea/Data/il2cppOutput/NativeFunctions.cpp:1:15: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
 <U+FEFF>extern "C" __declspec(dllexport) int __stdcall CountLettersInString(wchar_t* str)
                    ^
 /Users/...../project/Temp/StagingArea/Data/il2cppOutput/NativeFunctions.cpp:1:41: warning: '__stdcall' calling convention is not supported for this target [-Wignored-attributes]
 <U+FEFF>extern "C" __declspec(dllexport) int __stdcall CountLettersInString(wchar_t* str)
                                              ^
 1 warning and 1 error generated.


I'm using Unity 2020.1.8f1 on OS X 10.15.7.

Is there anyway I'm able to customize the compiler's arguments? Specifically so I can add -fdeclspec to the clang++ invocation.

Comment
Add comment · Show 2
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 JoshPeterson · Oct 12, 2020 at 12:41 PM 0
Share

Note that compiling this native code with the project won't avoid the performance costs of marshaling for p/invoke. That will still be necessary. Compiling with the project just provides a quick way to compile the native code.

I would recommend that you compile this native code separately as a library, that way you can use the specific compiler flags that you need.

avatar image IainTTGilfeather JoshPeterson · Jan 27, 2021 at 10:07 PM 0
Share

Regardless of the performance benefits, how do we get the c++ to compile? The documented function decoration, as used by the OP does not compile for me either. With the same error.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by funx · Oct 12, 2020 at 12:57 PM

Hi Thanks for the reply.

Quoting from the link above;

This significantly decreases the performance overhead of a P/Invoke call.

Am I misunderstanding something?

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 JoshPeterson · Oct 12, 2020 at 01:28 PM 0
Share

Yes, the performance improvement is not due to the lack of marshaling for the p/invoke call. All of that marshaling will happen no matter how native code is built.

The performance improvement is due to the fact that the native linker must link the method statically, rather than dynamically, so with link time optimization enabled, the linker can optimize across that function call. You can get this same benefit by compiling the native code separately into a static library.

avatar image funx JoshPeterson · Oct 12, 2020 at 02:27 PM 0
Share

Gotcha, thanks!

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

137 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 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

native android plugin 0 Answers

Overlay a native layer 0 Answers

Native Rendering Plugin with UI Image 0 Answers

Execute native plugins in edit mode? 1 Answer

Binding EGLImage to RenderTexture (or setting NativeTexturePtr) 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