是否有人建议如何使用C ++专门扩展Python 3?我尝试使用SWIG,但是在尝试访问计算机上不存在的库文件(Python_d.lib或类似文件)时,出现致命链接错误。

编辑:

我采取的步骤是:

1)从http://www.swig.org/download.html下载swigwin-2.0.4

2)设置环境变量(PYTHON_INCLUDE和PYTHON_LIB)

3)构建swigwin软件包随附的示例之一。此代码发布在下面。这是在MVSC ++ 2010中内置的。

/* File : example.c */

#include "example.h"
#define M_PI 3.14159265358979323846

/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
    x += dx;
    y += dy;
}

int Shape::nshapes = 0;

double Circle::area(void) {
    return M_PI*radius*radius;
}

double Circle::perimeter(void) {
    return 2*M_PI*radius;
}

double Square::area(void) {
    return width*width;
}

double Square::perimeter(void) {
    return 4*width;
}


我从中得到的输出的相关部分是:

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(C:\Users\David\Downloads\swigwin-2.0.4\Examples\python\class\.\Debug\example.dll) does not match the Linker's OutputFile property value (C:\Users\David\Downloads\swigwin-2.0.4\Examples\python\class\_example.pyd). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(991,5): warning MSB8012: TargetExt(.dll) does not match the Linker's OutputFile property value (.pyd). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(992,5): warning MSB8012: TargetName(example) does not match the Linker's OutputFile property value (_example). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).

1>LINK : fatal error LNK1104: cannot open file 'python32_d.lib'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:04.27

最佳答案

在MSVC中将构建配置从“调试”更改为“发行”,或检查对this question的回答。

关于c++ - 需要帮助以C++模块扩展Python 3.2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9394926/

10-10 23:19