1

我正在尝试使用我从 swig,org 下载的示例使用 Visual Studio 2010 创建我的第一个 SWIG python DLL。我正在运行 64 位 Windows 专业版。我下载了 swigwin-2.0.7 并解压。我已按照此处此处的说明进行操作,在这两种情况下,都会构建包装文件,但项目构建失败。链接器抱怨 56 个未解析的外部符号,所有符号的名称都类似于 __imp__PyBytes_AsStringAndSize 或 __imp__PyExc_RuntimeError。

我已经使用我的 python 2.7 安装以及我的 python 3.2 安装尝试了这个,结果相似。我必须从源代码为我的平台构建 swig 吗?我在这上面花了 6 个小时左右,我很困惑。

4

1 回答 1

3

Following the instructions here, using the simple Python example from SWIG, Windows 7 64-bit and Python 2.7 32-bit, I did not see the OP's specific errors. I saw:

1>example_wrap.obj : error LNK2019: unresolved external symbol "int __cdecl gcd(int,int)" (?gcd@@YAHHH@Z) referenced in function __wrap_gcd
1>example_wrap.obj : error LNK2001: unresolved external symbol "double Foo" (?Foo@@3NA)

Two changes had to be made due to the simple example being C source instead of C++:

  1. Do not use the -c++ switch on the swig command line (step 13 of the instructions).
  2. The generated file is now example_wrap.c not example_wrap.cxx (referred to in steps 14 and 19 of the instructions).

Alternatively, just rename example.c to example.cpp in this case before following the instructions and they should work as is.

于 2012-08-19T15:03:19.920 回答