Creating a DLL from a wrapped cpp file with SWIG

前端 未结 8 1906
刺人心
刺人心 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 20:54

    add MS_NO_COREDLL definition at Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions; or add #define MS_NO_COREDLL line before including python.h.

    #define MS_NO_COREDLL
    #include <Python.h>
    
    0 讨论(0)
  • 2021-01-02 20:54

    SWIG (at least on v3.0) generates the python.h inclusion in the wrapper as follows:

    #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)
    /* Use debug wrappers with the Python release dll */
    # undef _DEBUG
    # include <Python.h>
    # define _DEBUG
    #else
    # include <Python.h>
    #endif
    

    So when compiling a debug version of the wrapper on a Windows platform, we simply need to define the SWIG_PYTHON_INTERPRETER_NO_DEBUG flag to avoid the pyconfig.h file issue mentioned in Ken's answer.

    0 讨论(0)
  • 2021-01-02 20:54

    I resolved the missing python27_d.lib by doing the following:

    • Copy python27.lib to python27_d.lib
    • In pyconfig.h comment out define Py_DEBUG
    0 讨论(0)
  • 2021-01-02 20:58

    You can try adding "python27_d.lib" (without quotes) to ignored libs:

    Configuration Properties -> Linker -> Input -> Ignore Specific Library

    0 讨论(0)
  • 2021-01-02 21:00

    I found out that addind the Python symbols do the Project solves it. Do it like this

    I also copied the python27.lib to a file named python27_d.lib

    0 讨论(0)
  • 2021-01-02 21:03

    Building the project in Release mode removes the python27_d.lib dependency too; at least it did for my own project.

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