Search code examples
c++windowscompilationopenexr

Py ILM Base not compiling on windows


I've downloaded the latest copy from Latest Open EXR repo and compiled most everything without any problems. However, when I get to PyILMBase it fails.

There are two distinct issues with my attempts:

Error C2491 'PyImath::FixedArray::name': definition of dllimport function not allowed PyImath (...)\src\pyilmbase-2.2.1\PyImath\PyImath.cpp 41

and an import to unistd.h that kind of gets addressed Here

my question being, has anybody successfully compiled this for windows? It seems odd that I can't find any specific info about that compiling error. Am I missing something in the way that C++ works?

This project makes extensive use of whatever it is that causes the error C2491, so going in and changing it would be a little complicated


Solution

  • IlmBase is compiled as a shared library. A shared library must provide their function declarations in order your program can find them. It's perform by declaring them as dllimport or dllexport depending on the situation.

    • __declspec(dllimport): imports the implementation from a DLL so your application can use it.
    • __declspec(dllexport): tells the linker that you want this object to be made available for other DLL's to import. It is used when creating a DLL that others can link to.

    These keywords are generally handled by a single macro. In your case PYIMATH_EXPORT.

    These lines are from PyImathTask.h

    #if defined(PYIMATH_EXPORTS)                         // create library  
      #define PYIMATH_EXPORT __declspec(dllexport)  
    #else                                                // use library  
      #define PYIMATH_EXPORT __declspec(dllimport)  
    #endif
    

    So, because you want to make these functions available from your application, you must add PYIMATH_EXPORTS as a preprocessor definition.

    Actually, PyIMath's properties mispells it - they've write it as PyImath_EXPORTS - ... To fix that, in vs2015, go to the PyImath's properties > Configuration Properties > C/C++ > Preprocessor > Replace PyImath_EXPORTS by PYIMATH_EXPORTS.

    It's probably the same thing for PyIex...