Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 triangle4studios · Jun 01 at 06:38 PM · dllpluginsbuild errorc++linking

Custom dll does not work with build -> works with editor - Unity 2019.4.38f

I must be misunderstanding the documentation.

I have the following code in a dll compiled in c++:

 #include <cmath>
 #include <limits>
 
 
 struct Vector2
 {
    float x = 0, y = 0;
    Vector2 (float x, float y) : x(x), y(y) {}
    Vector2 () = default;
 };
 struct Vector3 
 {
       float x = 0, y = 0, z = 0;
       Vector3 (float x, float y, float z) : x(x), y(y), z(z) {}
       Vector3 () = default;
 };
 
 extern "C"__declspec(dllexport) float Radians(Vector2 a, Vector2 b)
 {
    return atan2f(a.y - b.y, a.x - b.x);
 }
 extern "C"__declspec(dllexport) float Angle(Vector2 from, Vector2 to)
 {   
    float angle = Radians(from, to) * (180.0f / (22.0f/7.0f));
    if (angle < 0.0f) 
          angle += 360.0f;
    return angle;
 }


I use the following g++ command to export:

 g++ -shared -o tMath.dll tMath.cpp -Wl,--out-implib,tMath.dll 

The files are placed in a folder called Plugins.

I Import the functions into my Math.cs Library Like so:

 [DllImport("Assets/Plugins/tMath.dll")]
 public static extern float Angle(Vector2 a, Vector2 b);


I am using the code in color tool I created. I don't need to use it, but I want to grow in more than one language as I develop, which is why I am trying to use c++ for my math functions.


Important details:

  1. The dll works fine in the editor.

  2. The dll works fine when it is first built. The second run and subsequent runs does/do not.

  3. The code works if I dont use the dll and instead use a C# variation of the same code.


However, it does not work when built, on any of my test computers. What am I missing?


This is a link to a video showing you the "second run" portion of the issue. This video clearly shows me that the dll is linked when running it the first time. After that there is no link, which points to the dll reference being still in memory, and the program accessing it. After closing and reopening, that reference is no longer there.


So there is obviously an issue with locating the DLL. I just cannot grasp what I am doing wrong.

Comment
Add comment · Show 1
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 triangle4studios · Jun 03 at 11:53 PM 0
Share

I am assuming by the lack of replies this is a complicated issue.

0 Replies

· Add your reply
  • Sort: 

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

139 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 avatar image avatar image

Related Questions

Unity plugins 0 Answers

DLLNotFoundException 0 Answers

How can I import and use a plugin/API? 0 Answers

return char** from C++ DLL 0 Answers

How to assign a function to UnityEvent without the use of lambdas? 1 Answer


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