Creating a DLL from a wrapped cpp file with SWIG

前端 未结 8 1907
刺人心
刺人心 2021-01-02 20:42

I am in the process of learning how to use SWIG on Windows.

The following is my c++ code:

 /* File : example.cxx */

 #include \"example.h\"
 #defin         


        
相关标签:
8条回答
  • 2021-01-02 21:06

    The problem seems to be that, for unknown reasons, the file pyconfig.h FORCES the use of a specifically named .lib file. OUCH! Frankly, this looks like a bug to me - let the programmer specify what .lib file to use! Don't force it!

    In the code below, you could simply #ifdef 0 the entire thing, or rename "python27_d" to "python".

    Anyway, here is the offensive code from pyconfig.h:

    /* For an MSVC DLL, we can nominate the .lib files used by extensions
    */
    #ifdef MS_COREDLL
    #   ifndef Py_BUILD_CORE /* not building the core - must be an ext */
    #       if defined(_MSC_VER)            /* So MSVC users need not specify the .lib file in          their Makefile (other compilers are generally           taken care of by distutils.) */
    #           ifdef _DEBUG
    #               pragma comment(lib,"python27_d.lib")
    #           else
    #               pragma comment(lib,"python27.lib")
    #           endif /* _DEBUG */
    #       endif /* _MSC_VER */
    #   endif /* Py_BUILD_CORE */
    #endif /* MS_COREDLL */
    
    0 讨论(0)
  • 2021-01-02 21:08

    If you look in the libs directory of your Python installation I suspect you will find a python27.lib and not a python27_d.lib. I believe that the _d.lib is the debug version of the Python library and your Python installation didn't include it. Elsewhere I've seen it suggested that the simplest way around this is to download the Python sources and build the release and debug versions yourself but I've never tried this. Alternatively change you build to use the release version of the Python .lib. You should be able to debug your own code but not the Python code then.

    0 讨论(0)
提交回复
热议问题