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

expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386.

Discussion in 'Editor & General Support' started by Todd-Wasson, Sep 18, 2015.

  1. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    I'm trying to create a native plugin (C++) to run in Unity. My dll is called "FFConst.dll" and is sitting in the plugins folder like it should be. I followed the Unity video on plugins, but I've hit a most frustrating snag. Here's the error I get:


    Code (csharp):
    1.  
    2. Failed to load 'Assets/Plugins/FFConst.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.
    3.  
    I've checked around and about all I've found to do in Visual Studio 2012 is to change my dll project's properties as follows and shown in the picture below:

    1) Linker->SubSystem to Console
    2) Target Machine to MachineX64
    3) Configuration Manager to x64

    This should be outputting a 64 bit dll that Unity can load, right? Does anyone have any idea what I could be missing here? I'm using the 64 bit version of Unity and have my application build settings set to x64. Not sure what else I can do. I don't know if Visual Studio is just outputting a 32 bit dll regardless of these settings or if Unity is just not reading it in correctly or what.



    64bit.jpg
     
    uichunter likes this.
  2. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Visual Studio appears to not be building the 64 bit version of the dll at all, which explains why Unity is complaining about a 32 bit version. VS says build succeeded but the file is nowhere to be found. WTF... Anyone run into this before or know what I might be missing?
     
  3. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Bah, nevermind. When I switched from 32 to 64 bit, VS also changed the output from a dll to an exe. No idea why, but there you go. Solution was as follows:

    Project->Properties (bottom of menu)->Configuration Properties->General

    On right pane under Project Defaults, the Configuration Type needed to be changed back to Dynamic Library (.dll).
     
  4. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    NEW PROBLEM:

    Now I'm trying to go the other way and make my game a 32 bit version. I've created a 32 bit version of my native plugin dll, and am now getting this same message.

    My player settings in the build menu is x86:

    Unityx86.png

    Why is Unity failing to load this and giving me a message that it expects a 64 bit version of the dll? I have restarted Unity and rebuilt and copied the dll over while Unity is not running several times.

    When I click my plugin and view it in the inspector, I have it set to x_86 too. So as far as I can see I've got 32 bit across the board but Unity is still telling me to make a 64 bit version of the plugin to run with my now 32 bit game? o_O

    Unity inspector my dll.png

    I've tried every combination of checks there including none but the results are the same. What in the world is going on here?
     
    Last edited: Nov 12, 2015
  5. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Ok, I think I've finally figured this out so will explain it here for future generations. I'm not entirely sure this is all correct, but it's the best I've been able to figure out:

    I'm running 64 bit Unity. I'm pretty sure that 64 bit Unity needs a 64 bit version of my plugin in order for the editor to be able to use it. I.e., when I built a 32 bit version of the game with the 32 bit version of my plugin, the built game worked fine, but it wouldn't work in the editor because 64 bit Unity wants a 64 bit version of the plugin. "Well duh," you say, but I didn't know that.

    Here's how I fixed it:

    Because I'm using 64 bit Unity and wanted to make a 32 bit build of the game, I needed two plugins:

    1) A 64 bit version of the plugin for the Editor. Why? Because a 64 bit editor can't read a 32 bit plugin. I didn't realize this, but it makes sense now. If you press play, a 64 bit Editor is trying to run a 32 bit plugin, so it says "hey, dummy, I'm a 64 bit editor so I need a 64 bit version of your plugin to use when you're running your game in me. If you want a 32 bit plugin for the built version of the game, that's ok to have too, but I still need a 64 bit plugin to play your game in the editor because I am a 64 bit editor."

    2) A 32 bit version of the plugin for the built game which is 32 bit.

    Ok, so, I've got two plugins now: One is 64 and the other is 32. The 64 bit one in my case is only there for the 64 bit editor to run. The next part was setting up the plugins in the inspector. Unity has a lovely doc on this right here: http://docs.unity3d.com/Manual/PluginInspector.html

    There are two folders in the plugins folder. One is x86 and the other is x86_64. I put the 32 bit plugin in the first folder and the 64 bit in the second. For each plugin you then have to adjust their settings so Unity knows how to use them. Clicking the plugin in the folder bring this up:


    plugin inspector 32-1.png


    Those are the 32 bit plugin settings for the editor (as opposed to the settings for the built game). The checkboxes mean there are settings for editor and standalone. I don't want to use the 32 bit plugin for the editor (I'm using Unity 64 on a 64 bit machine), so I had to make sure to turn it off. On my machine (64 bit CPU and 64 bit Unity) I told the Editor to ignore the 32 bit plugin by setting the CPU to x86 (32 bit). So Unity will not try to use this 32 bit dll unless my CPU is a 32 bit now. That shuts it off, the Unity editor will just ignore it.

    Next up is the build setting for the 32 bit dll:

    plugin inspector 32-2.png

    Under Platform settings is a little down arrow. These are the build settings. By checking both x86 and x86_x64 here Unity knows to use this 32 bit dll in both 32 and 64 bit versions of Windows on the built version of the game.

    Now for the 64 bit dll. In my case I wanted this to only be used for the editor. (My big problem in all this was in not realizing a 64 bit version would even be needed, but it makes sense since my version of Unity is 64 bit).

    So I click on the 64 bit version of the plugin and view the inspector.

    plugin inspector 64-1.png

    The reason "editor" and "standalone" are both checked is because I want settings for both of those (this goes for the earlier 32 bit stuff as well). I want to say "editor, you should use this version of the dll," and I want to say, "built version, you should NOT use this version of the dll."

    The picture above shows the editor setting. It's set on X84_64 and Windows (my CPU and OS) so the 64 bit Unity editor will use the 64 bit plugin in the editor. So that's the version of my plugin Unity will use when playing the game in the editor.

    Now for the build settings. In my case I did not want to use a 64 bit version at all for a build (32 bit build only), so here's how that's set up:

    plugin inspector 64-2.png

    Here I'm saying "do not use this plugin for either 32 or 64 bit Windows." In other words, don't use this 64 bit plugin in the build because the build is going to be 32 bit so it needs to use the 32 bit plugin instead of this 64 bit version.

    This solved all problems and created ever lasting peace in the universe.
     
    JachinWu and Baste like this.
  6. AndreaT_49

    AndreaT_49

    Joined:
    Feb 19, 2016
    Posts:
    1
    thx so much! Worked well!
     
    Todd-Wasson likes this.
  7. MaxSimon

    MaxSimon

    Joined:
    Apr 13, 2016
    Posts:
    1
    thx so much! Worked well!
     
    Todd-Wasson likes this.
  8. uichunter

    uichunter

    Unity Technologies

    Joined:
    Feb 23, 2016
    Posts:
    5
    Cool man. You save my time!
     
    Todd-Wasson likes this.
  9. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,307
    I also stuck at this stage. My dll file had no problem at unity 4.6 era, but I now tried to open it at unity 5.5 beta, errors like yours occur.

    So how can I know my dll is for 32 bit? (I got this dll from other developer, not myself created)

    And how can I recompile that dll for 64 bit?

    How you get 64 bit dll from your 32 bit dll file?
     
  10. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    If you're getting the error then it's probably the wrong version. If you want to check for sure, this will probably do it:

    http://www.dependencywalker.com/

    You can't recompile a dll. You need the project (source, etc).. and then can recompile to 64 or 32 from the compiler.

    Same answer. I'd recommend you first ask the developer if they can compile a 64 bit version for you. In Visual Studio it's just a couple clicks to output a 32 or 64 bit version.
     
  11. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,307
    Thanks, anyway, I installed 32 bit unity 5.5.0 beta, so there is no problem now with same 32 bit dll.
    So problem can be solved by unity 32 bit.
     
  12. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Ok, if that works for you then go for it.

    The reason is that you need a dll version that matches whatever version of Unity you're using and another one for the built game. If you're building a 32 bit game you need a 32 bit dll, and if you're using 64 bit Unity to build it then Unity needs a 64 bit version of the dll too. If everything is 64 bit (Unity and your built game) then all you need is a 64 bit version. If everything is 32 bit then all you need is a 32 bit version.

    If later you decide you want to run 64 bit Unity again with that, you'll need to get a 64 bit version of the dll from the creator of it or get the source/project so you can compile one yourself in Visual Studio or whatever. There's no way to convert a dll from one to the other, it has to be compiled that way.