gpt4 book ai didi

c++ - 需要帮助使用 C++ 模块扩展 Python 3.2

转载 作者:行者123 更新时间:2023-11-28 03:40:37 24 4
gpt4 key购买 nike

有没有人对如何使用 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 中将构建配置从 Debug 更改为 Release,或查看 this question 的答案.

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com