Python 3をC++で拡張する方法の提案はありますか?私はSWIGを使用しようとしましたが、私のコンピュータに存在しないライブラリファイル(Python_d.libなど)にアクセスしようとすると、致命的なリンクエラーが発生します。C++モジュールでPython 3.2を拡張するのに助けが必要です
編集:私が撮った
の手順は以下の通りであった。
1)は、環境変数(PYTHON_INCLUDEとPYTHON_LIB)
の設定http://www.swig.org/download.html
2)からswigwin-2.0.4をダウンロード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
SWIGエラーの解決について質問してください(あなたが行ったことの詳細と関連するコードと正確なコンパイラエラーを入力してください)。あなたがそれを構築することができなかったからといって、使用するのが正しいことではありません。 – Mat
@Matは次のように言っています。具体的な質問(モジュールのインターフェースの外観、コンパイルのための実行内容、エラーメッセージの内容)を投稿すると、人々はそれを修正できます。それが立てば、この疑問は非常に曖昧でオープンなものです。 – Flexo
それは当時私が大学にいて、細かいことがなかったので、他の人がPython 3をC++で動かすためにどのような手順を取ったのか見たいと思っていました。元の投稿にできるすべての情報を追加しました。 – Tagc