• 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 Ensutee · Apr 16, 2013 at 05:01 PM · dllnotfoundexception

DllNotFoundException, multiple C# and C++ DLLs

We have a project which is using several dlls, these are:

  • GuitarNotes.dll (C#)

  • Bass.Net.dll (C#)

  • bass.dll (C++)

  • bassasio.dll (C++)

  • fftwlib.dll (C#)

  • libfftw3-3.dll (C++)

We have these dlls place in the three following places:

  • Project/Assets/Plugins folder

  • Project

  • (Program Files)/Unity/Editor

As suggested by just about every thread about DllNotFoundException we've found.

For a bit of reference-clarity, GuitarNotes.dll references Bass.Net.dll and fftwlib.dll. Bass.Net.dll references bass.dll and bassasio.dll and fftwlib.dll references libfftw3-3.dll.

We have a script that only interacts with GuitarNotes.dll. The first thing GuitarNotes.dll does upon use is to utilize Bass.Net.dll (and its wrapped C++ DLLs) for some setup and audio recording after which it proceeds to use fftwlib.dll to call functions in libfftw3-3.dll to perform FFTs (surprise!). We do not directly use anything but GuitarNotes.dll.

Initially Unity could not find bassasio.dll, but after placing it in both Project/Assets/Plugins and Project (root) it was found. Unity now proceeds to not find libfftw3-3.dll no matter how many of the above three places it is placed. How can this be?

We've tried importing the libfftw3-3.dll functions using [DllImport ("libfftw3-3")] to no avail, which honestly didn't surprise us much since both Bass C++ DLLs worked fine as soon as they were placed as mentioned.

EDIT: We have Unity Pro, so that's not the problem ;).

Comment
Add comment · Show 10
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 whebert · Apr 16, 2013 at 05:44 PM 0
Share

Even though you tried [DllImport ("libfftw3-3")], did you also define a static extern method to use inside that library and then call it first?

I had this same issue when I was using GDAL to dynamically access terrain data. I had my own C++ DLL that depended on GDAL and the only way to get it to work nicely without having to stick the GDAL DLL next to the .exe was to define an extern for a method inside the GDAL dll and to call it before I called any method in my own libarary, thus forcing Unity to load the dependent DLL first. And I stuck all my DLLs into the Assets/Plugins folder.

avatar image Ensutee · Apr 16, 2013 at 06:43 PM 0
Share

Initially we had this piece of code:

 using UnityEngine;
 //using GuitarNotes;
 using System.Collections;
 using System.Runtime.InteropServices;
 using fftwlib;
 
 public class GuitarInput : $$anonymous$$onoBehaviour {
     
     [DllImport ("libfftw3-3")]
     public static extern System.IntPtr malloc();
     
     // Use this for initialization
     void Start () {
         
         fftw.malloc(5*8);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

which produced the following error:

  • DllNotFoundException: libfftw3-3.dll

  • GuitarInput.Start () (at Assets/Plugins/GuitarInput.cs:15)

we then tried changing it to:

 using UnityEngine;
 //using GuitarNotes;
 using System.Collections;
 using System.Runtime.InteropServices;
 using fftwlib;
 
 public class GuitarInput : $$anonymous$$onoBehaviour {
     
     [DllImport ("libfftw3-3")]
     public static extern void cleanup();
     
     // Use this for initialization
     void Start () {
         
         cleanup();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

to call a function within the c++ dll, which produced the following error:

  • DllNotFoundException: C:/Users/Ensutee/Documents/BA_project/Assets/Plugins/libfftw3-3.dll

  • GuitarInput.Start () (at Assets/Plugins/GuitarInput.cs:15)

So basically the same error :/

avatar image whebert · Apr 16, 2013 at 06:48 PM 0
Share

And libfftw3-3.dll was in your Assets/Plugins folder when you tried the above?

avatar image Ensutee · Apr 16, 2013 at 07:03 PM 0
Share

Yes it was.

avatar image whebert · Apr 16, 2013 at 07:37 PM 0
Share

Just downloaded the 32 bit version, put the DLL in Assets/Plugins, put this in my script and it worked. I had to change your "cleanup()" to "fftw_cleanup()" to get it to work.

 [DllImport ("libfftw3-3")]
 public static extern void fftw_cleanup();
     
 // Use this for initialization
 void Start () {
         
    fftw_cleanup();
 }
avatar image Ensutee · Apr 16, 2013 at 07:38 PM 0
Share

We are using the 32 bit version, just gonna give your version a try and report back.

avatar image Ensutee · Apr 16, 2013 at 07:42 PM 0
Share

We're still getting the DllNotFoundException. We are going to try to see if we can get it to work in a new project, i.e. on a clean slate.

avatar image whebert · Apr 16, 2013 at 07:45 PM 0
Share

And I'd make sure no other script was trying to access any other DLL that might be dependent on libfftw3-3.dll before you try fftw_cleanup()... you have to be the first to try to access that DLL to get this to work.

avatar image Ensutee · Apr 16, 2013 at 07:56 PM 0
Share

Okay... So apparently we were in fact using the 64 bit version. Awkward. It surprises me that a separate Visual Studio project works with all 32-bit code and the same DLLs (including libfftw3-3 as 64-bit). But whatever. $$anonymous$$any thanks and hugs to you!

avatar image whebert · Apr 16, 2013 at 08:04 PM 0
Share

In my case, the 64 bit version of GDAL worked in the Editor and in the build on my computer, but when we put the build on another computer it caused the DLLNotFoundException. That tripped us up for a while.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whebert · Apr 16, 2013 at 07:28 PM

And are you using the 32 bit version of libfftw3-3.dll? I had issues when I mistakenly used the 64 bit version of GDAL and it all cleared up when I switched to the 32 bit version. Assuming your Unity build is 32 bit.

Comment
Add comment · Show 3 · 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 Ensutee · Apr 16, 2013 at 08:30 PM 0
Share

Thanks to whebert, the answer is make sure you're not mixing 64-bit and 32-bit libraries.

avatar image levend · Jun 16, 2015 at 07:48 AM 0
Share

Hi whebert,

I tried to use GDAL(C# wrapper) from Unity but I failed. I have a post about this:

http://answers.unity3d.com/questions/981407/using-gdal-from-unity.html

$$anonymous$$aybe I can use the GDAL C++ lib like you. However, I am confused, I do not know what can I do exactly. Can you explain the all steps about using GDAL C++ lib from Unity briefly?

Thanks...

avatar image whebert · Jun 19, 2015 at 03:57 AM 0
Share

Hello levend,

I saw your post concerning the use of GDAL in Unity. Like this thread mentions, are you insuring that the GDAL dll is a 32 bit version of the library? If you attempt to use a 64 bit version and are building a 32 bit Unity application, you will likely encounter issues.

I saw the error you posted and the part about "... is not a valid Win32 application" sort of sounds like this may be the case.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

dll not found exception when c++ methods are call from multiple threads 0 Answers

Error building Player: Extracting referenced dlls failed. 1 Answer

Dll is not allowed or could not be found 0 Answers

Using Java libraries in Unity C# project through IKVM.net: msvcrt dll-not-found 2 Answers

Cannot load native dll in WebGL build 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