I’m having a curious error when trying to import the Phidgets library into my projects on OSX.
The C# DLL is correctly detected by Unity and compiled with the rest of my code. When I sync the project, the DLL’s methods are available when I am using the library. However, once I hit play, I get: “DllNotFoundException: phidget21.dll” I’ve tried putting the DLL everywhere.
I’m not familiar enough with how Unity3D sets it’s references to DLLs to properly debug this problem. The reference to the DLL is correctly appearing under References in the SLN. I’m hoping someone that’s more familiar with C# DLLs can give me a couple of pointers on why this is occurring.
The Phidgets plug-in is located here: Language - C Sharp - Phidgets Support
You don’t actually need any Phidgets to see the problem. Just import the DLL following the directions on the site (It’s the Phidget21.NET file), then try creating any Phidgets object to see the problem.
One thing of note is the site includes the following directions:
One more thing needs to be done before you can compile and run the
examples. You need to set up a special
configuration file so that Mono knows
where to find the phidget21.dll. Since
Mac does not use dll’s you need to
redirect it to the appropriate file.
Create a new file in the same
directory as the example you wish to
compile and name it
Phidget21.NET.dll.config. Put the
following into the file:
<dllmap dll="phidget21.dll" target="/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21"
/>
I haven’t the first idea how to target this DLL correctly w/ Unity… Any suggestions?
OK, figured it out.
You need to edit a file within the Unity.app!
Go to the Unity.App file in your Applications → Right Click Show Package Contents
Now find this file:
Contents/Frameworks/Mono/etc/config
That config file is what you need. Open that up in a text editor and add:
<dllmap dll="phidget21.dll" target="/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21" />
Wha lah!
Hi
i need some help.
When I run the project in Unity 3D, the phidgets run at 100%. But when I do the build for MAC OSX can not connect. The build for Windows works well.
Need to copy any files into the package of Mac OSX?
I created a BuildPostProcessor that automates this for you…
Copy the following class and put it in the /Editor folder in your relevant projects.
This code should run after the build finished:
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Xml;
public class PhidgetOSXBuildPostprocessor
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
if(target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal)
{
//add a dll map to the build..
string dllConfigFileName = pathToBuiltProject+"/Contents/Data/Managed/etc/mono/config";
XmlDocument doc = new XmlDocument();
doc.Load(dllConfigFileName);
XmlElement dllmap = (XmlElement) doc.CreateNode(XmlNodeType.Element, "dllmap", "");
dllmap.SetAttribute("dll", "phidget21.dll");
dllmap.SetAttribute("target", "/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21");
doc.DocumentElement.AppendChild((XmlNode) dllmap);
doc.Save(dllConfigFileName);
}
}
}
Thank you so much. Still Usefull in 2018 now with Phidgets 2.2 and unity 2018.1 its a bit different though.
There are 2 Config Files now in “YourUnityProject.App”. They are located at:
…\YourUnityProject.App\Contents\Mono\etc\mono
…\YourUnityProject.App\Contents\MonoBleedingEdge\etc\mono
and you need to do modify the dllmap a bit. insert:
<dllmap dll="phidget22" target="/Library/Frameworks/Phidget22.framework/Versions/Current/Phidget22" />
(notice no .dll)
I hope I could help anybody still searching for a solution