链接器错误1120尝试使用setuptools / distutils为python构建c ++扩展时

时间:2017-02-10 01:48:48

标签: python c++ linker swig distutils

我正在使用C ++(扩展名为.pyd)创建一个动态库,它将静态C ++库与它捆绑在一起。目的是在Python中导入库并在我当前的测试框架中使用它。

我按照文档编写并使用swig生成.cxx文件。然后我写了一个distutils setup.py文件,如下所示:

from distutils.core import setup, Extension    
xy = Extension('_xy',
                                   sources='xy_wrap.cxx','main.cpp',],
                                   include_dirs = [r'<project>\Include',r'<project>\Source'],
                                    library_dirs = [r'<libdir>\Release',r'C:\Python27\libs'],
                                    libraries = ['xy ','python27'],
                                    )

setup (name = 'xy',
           version = '0.1',
           author = "Rivas",
           description = """The Library Interface which can be used for automation""",
           ext_modules = [xy_module],
           py_modules = ["xy"],
           )

我也在使用VS 9.0来编译python源代码。编译似乎经历了但它标记了一个链接器错误,并且似乎都链接到链接器没有找到正确的库文件(python以及我自己的)。我在下面提出的错误示例。

    Creating library build\temp.win-amd64-2.7\Release\_xy.lib and object build\temp.win-amd64-2.7\Release\_xy.exp
        PyCSPSDKLite_wrap.obj : error LNK2019: unresolved external symbol __imp__PyString_FromString referenced in function "struct _object * __cdecl SWIG_Python_str_FromChar(char const *)" (?SWIG_Python_str_FromChar@@YAPAU_object@@PBD@Z)
        PyCSPSDKLite_wrap.obj : error LNK2019: unresolved external symbol __imp__PyExc_RuntimeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPAU_object@@H@Z)
        PyCSPSDKLite_wrap.obj : error LNK2019: unresolved external symbol __imp__PyExc_AttributeError referenced in function "struct _object * __cdecl SWIG_Python_ErrorType(int)" (?SWIG_Python_ErrorType@@YAPAU_object@@H@Z)
...    
: fatal error LNK1120: 59 unresolved externals

我已经包含了库目录以及相关的二进制文件,但这似乎仍未解决问题。

有人能指出我正确的方向吗? [注意:我已将项目重命名为xy]

0 个答案:

没有答案