Search Unity

Building native dll

Discussion in 'macOS' started by RyuMaster, Oct 8, 2016.

  1. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    Hi! I am very new to Mac, and spent almost full day trying to sort this out. I want to build c++ dll to call both from window and mac using XCode. So I've made XCode C++ dynamic library app, with setting like this:

    mySettings.png

    and I have very simple function in header

    Code (csharp):
    1. extern "C" int __stdcall GetInfo();
    and cpp immplementation

    Code (csharp):
    1.  
    2. extern "C"
    3. {
    4.   int GetInfo()
    5.   {
    6.       return 152;
    7.   }
    8. }
    [

    This compiles on mac just fine as dylib.

    Then, inside Unity, I add it as:

    Code (csharp):
    1.  
    2.     [DllImport("libLibea", EntryPoint = "GetInfo")]
    3.     public static extern int GetInfo();
    4.  
    and end up getting error:

    Code (csharp):
    1.  
    2. Can't find PE header for Assets/Plugins/x64/libLibea.dll
    3. Failed to load 'Assets/Plugins/x64/libLibea.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_UNKNOWN. You must recompile your plugin for 64 bit architecture.
    4.  
    What else am I missing? My architecture is universal. Maybe the problem, is that I rename dylibto dll, without doing something else important?
     
  2. 686InSomNia686

    686InSomNia686

    Joined:
    Nov 28, 2012
    Posts:
    9
    First of all, for Mac, you need to build a BUNDLE library to be used by Unity.
    Secondly, I advise you to work with CMake and SWIG to build cross-platform (Windows & Mac) and to have a free wrapper.