Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

NativePlugin Changes in 5.2.X broke the Simplest Plugin Example

Discussion in 'Scripting' started by tgraupmann, Oct 27, 2015.

  1. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    http://docs.unity3d.com/Manual/PluginsForDesktop.html

    Simplest Plugin
    This plugin project implements only some very basic operations (print a number, print a string, add two floats, add two integers). This example may be helpful if this is your first Unity plugin. The project can be found here and includes Windows, Mac, and Linux project files.

    http://docs.unity3d.com/uploads/Main/SimplestPluginExample-4.0.zip

    Unfortunately, the SimplestPluginExample doesn't work in 5.2.1 or 5.2.2.

    Loading the most basic plugin results in the following errors.

    Failed to load 'Assets/Plugins/ASimplePlugin.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

    Failed to load 'Assets/Plugins/ASimplePlugin.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

    Failed to load 'Assets/Plugins/ASimplePlugin.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

    Failed to load 'Assets/Plugins/ASimplePlugin.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

    Failed to load 'Assets/Plugins/ASimplePlugin.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.
    PluginImport:Start() (at Assets/PluginImport.cs:25)
    PluginImport:Start() (at Assets/PluginImport.cs:21)

    DllNotFoundException: Assets/Plugins/ASimplePlugin.dll
    PluginImport.Start () (at Assets/PluginImport.cs:21)

    Reported in the bug reporter.

    (Case 739744) Native Plugins Aren't working in 5.2.1 or 5.2.2

    Tested on WIndows 10 (64-bit)
     
  2. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    319
    Have you tried recompiling the plugin for 64-bit?
     
    Kiwasi likes this.
  3. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Yes I tried 64-bit. But there's a few places that I had to change. First I needed to add the x64 target. Then in configuration settings to make sure that target was being built. And then in the project general settings, add x64 output folders. And then linker->Advanced set the target machine to MachineX64. Okay that did it. Maybe add the x64 target to the referenced project. Not sure why 32-bit wouldn't load?
     
  4. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Not being able to load 32-bit plugins seems like a problem. Not every plugin needs to be 64-bit right?

    Especially since i can't get the 64-bit libraries in some cases.
     
    Last edited: Oct 27, 2015
  5. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I discovered a 64-bit loading issue. After compiling for x64, if any code calls a 64-bit static library, the native plugin will not load.

    Failed to load 'Assets/Plugins/EmotivPlugin.dll' with error 'The operation completed successfully.
    ', GetDllDirectory returned ''. If GetDllDirectory returned non empty path, check that you're using SetDirectoryDll correctly.

    Failed to load 'Assets/Plugins/EmotivPlugin.dll' with error 'The operation completed successfully.
    ', GetDllDirectory returned ''. If GetDllDirectory returned non empty path, check that you're using SetDirectoryDll correctly.
    EmotivPlugin:Awake() (at Assets/EmotivPlugin.cs:13)
    EmotivPlugin:Awake() (at Assets/EmotivPlugin.cs:12)

    DllNotFoundException: Assets/Plugins/EmotivPlugin.dll
    EmotivPlugin.Awake () (at Assets/EmotivPlugin.cs:12)

    I think this has something to do with linking to a static library and calling from a native plugin.

    Reported as case # with attached repro project.

    (Case 740144) Unity 5.2.2 Is not able to load native plugins that use static libraries
     
  6. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Solved the 64-bit issue. Not only did I need to statically link with the lib but I needed the premium edk.dll in the Assets/Plugins folder.