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
2
Question by XiaoClouds · Nov 20, 2011 at 04:50 PM · pluginnative plugindllnotfoundexception

DllNotFound when the plugin c++ dll links another c++ dll

I want to call c++ function in C# script. So I put the c++ dll in Assert/Plugins. However, if this dll (call it MainDll) dynamically links to another dll (call it SecondaryDll, which is also put into the Plugins folder), I will always get a DllNotFoundException.

I even write a VS C# project and calls MainDll linked with SecondaryDll in the same way as above, and everything is fine. Only not work in Unity C# script...

EDITED: No, just the MainDll as posted:

[DllImport("MainDll")] public static extern void FunctionMain1();

And in .cpp file which defines FunctionMain1, FunctionSec1 will be referenced, which I think is a purely c++ dynamic link:

// MainDll.cpp

include "SecondaryDll.h" extern "C" { DLL_EXPORT void FunctionMain1() { FunctionSec1(); } }

Also, SecondaryDll may exports C++ class since it is intended to be referenced only by another c++ project rather than unity c# script, like:

// MainDll.cpp

include "SecondaryDll.h" CSecondaryDll gObj;

extern "C" { DLL_EXPORT void FunctionMain1() { gObj.fun(); } }

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 aldonaletto · Nov 20, 2011 at 06:17 PM 0
Share

Are you declaring both libraries and their functions? Like this:

    [DllImport("$$anonymous$$ainDll")]
    public static extern void Function$$anonymous$$ain1();
    [DllImport("$$anonymous$$ainDll")]
    public static extern void Function$$anonymous$$ain2();
    ...
    [DllImport("SecondaryDll")]
    public static extern void FunctionSec1();
    [DllImport("SecondaryDll")]
    public static extern void FunctionSec2();
    ...
avatar image aldonaletto · Nov 21, 2011 at 03:36 AM 0
Share

As @Sister$$anonymous$$y said in a comment, the Your answer box must be used only to answer the question - comments and replies must be posted using the add new comment button. I added the text to your question, and deleted the answer to make things clearer.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Nov 21, 2011 at 03:46 AM

I never worked with more than one DLL in Unity, but I suspect that the problem is the SecondaryDll library location: since you've not declared it, Unity doesn't store this library wherever it's storing MainDll, and MainDll can't find it. You could try to declare any of the SecondaryDll functions in the same script you're declaring MainDll - I suppose Unity will store both in the same folder, allowing MainDll to find SecondaryDll. Another possibility would be to place SecondaryDll in the folder System32, the default DLL location - but this would complicate things when installing your game in another machine.

Comment
Add comment · Show 6 · 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 XiaoClouds · Nov 21, 2011 at 07:15 AM 0
Share

aldonaletto, thanks for your suggestions. But I wonder it may be not so easy to declare SecondaryDll's functions, since it can be from 3rd part, only export c++ classes and have no source.

avatar image aldonaletto · Nov 21, 2011 at 12:51 PM 0
Share

If you know at least one function declaration, you can declare it to test this. If not, try to store the DLL in the Windows/System32 folder - if this works, you will know that it's a location problem.

avatar image Tseng · Nov 21, 2011 at 01:21 PM 0
Share

You could of course also link the secondary Dll dynamically. Every 3rd party worth it's salt also delivers .lib files together with their .dlls

avatar image XiaoClouds · Nov 21, 2011 at 01:31 PM 0
Share

aldonaletto, I've tried storing dll in System32, but this doesn't work. I also tried export a dummy method in SecondaryDll and declare it in C# script; but only when C# code has called this dummy method, then it can successfully load Function$$anonymous$$ain1() which relies on the SecondaryDll. As you said, this is truly a path-searching problem. I find this post in forum (http://forum.unity3d.com/threads/28069-Plugin-consisting-of-multiple-dll-s-(F$$anonymous$$OD)) presents exactly the same issue, but also no better solution...

The solution of dummy method has drawbacks, since the SecondaryDll may depends on the third dll or even more, so it is a nightmare if all needs a dummy method...

avatar image abhinandan · Feb 01, 2012 at 01:19 AM 2
Share

i hope this issue has been fixed ..if not in my case i just placed the secondary dlls in unity application's root directory and it worked fine..

Show more comments
avatar image
0

Answer by mdeletrain · Nov 21, 2011 at 01:53 PM

A temporary solution could be to pre-merge your dll's using library tools and to put the merged dll into Unity. This way you only have one library and problem is gone... but yeah, it's quite an awful solution !

Comment
Add comment · Show 1 · 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 XiaoClouds · Nov 21, 2011 at 02:24 PM 0
Share

Actually, even for just one custom dll, it is not alone but depends on several windows system dlls. Unity can successfully load the first dll, which proves it can find the system dlls. Now the problem is unity did not know the path of secondary custom dlls, is it?

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

7 People are following this question.

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

Related Questions

Linux build is putting libNative.so in wrong place 1 Answer

Do Native Mobile Plugins Require Pro? 1 Answer

Why is GL.IssuePluginEvent not listed on documentation page for "GL" class? 0 Answers

Native Plugin: What has to happen in the RenderEvent? 1 Answer

low level native render plugin Xcode issues 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