LNK1120在构建引用 Boost 的 Python 包时



我正在尝试使用Boost.Python将Python集成到我的C++程序中。我已经能够很好地编译一些模块,但是这个模块一直给我链接器错误,抱怨来自boost-system的未解析的外部。

我有以下模块:

BOOST_PYTHON_MODULE(platform)
{
    boost::python::class_<mandala::platform_win32_t, boost::noncopyable>("platform", boost::python::no_init)
        .def("get_window_title", &mandala::platform_win32_t::get_window_title);
}

以及以下setup.py脚本:

from distutils.core import setup
from distutils.extension import Extension
setup(name='mandala',
    ext_modules=[
        Extension('platform',
            ['../mandala/platform_win32.cpp'],
        include_dirs=['C:\boost_1_55_0',
        '..extglm-0.9.4.4',
        '..extglew-1.10.0include',
        '..extglfw-3.0.1.bin.WIN32include'],
        library_dirs=['C:\boost_1_55_0stagelib',
        '..extglfw-3.0.1.bin.WIN32lib-msvc110',
        '..extglew-1.10.0libReleaseWin32'],
        libraries=['glfw3', 'glew32', 'opengl32', 'user32', 'gdi32']
        )
    ])

运行它时,我得到以下输出。

running build
running build_ext
building 'platform' extension
C:Program Files (x86)Microsoft Visual Studio 12.0VCBINcl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:boost_1_55_0 -I..extglm-0.9.4.4 -I..extglew-1.10.0include -I..extglfw-3.0.1.bin.WIN32include -IC:Python27include -IC:Python27PC /Tp../mandala/platform_win32.cpp /Fobuildtemp.win32-2.7Release../mandala/platform_win32.obj
platform_win32.cpp
C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDExlocale(337) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
c:python27includepymath.h(22) : warning C4273: 'round' : inconsistent dll linkage
        C:Program Files (x86)Microsoft Visual Studio 12.0VCINCLUDEmath.h(516) : see previous definition of 'round'
C:Program Files (x86)Microsoft Visual Studio 12.0VCBINlink.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:boost_1_55_0stagelib /LIBPATH:..extglfw-3.0.1.bin.WIN32lib-msvc110 /LIBPATH:..extglew-1.10.0libReleaseWin32 /LIBPATH:C:Python27libs /LIBPATH:C:Python27PCbuild glfw3.lib glew32.lib opengl32.lib user32.lib gdi32.lib /EXPORT:initplatform buildtemp.win32-2.7Release../mandala/platform_win32.obj /OUT:buildlib.win32-2.7platform.pyd /IMPLIB:buildtemp.win32-2.7Release../mandalaplatform.lib /MANIFESTFILE:buildtemp.win32-2.7Release../mandalaplatform.pyd.manifest
   Creating library buildtemp.win32-2.7Release../mandalaplatform.lib and object buildtemp.win32-2.7Release../mandalaplatform.exp
platform_win32.obj : error LNK2019: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z) referenced in function "public: __thiscall boost::detail::shared_count::shared_count<void *,struct boost::python::converter::shared_ptr_deleter>(void *,struct boost::python::converter::shared_ptr_deleter)" (??$?0PAXUshared_ptr_deleter@converter@python@boost@@@shared_count@detail@boost@@QAE@PAXUshared_ptr_deleter@converter@python@2@@Z)
buildlib.win32-2.7platform.pyd : fatal error LNK1120: 1 unresolved externals
Press any key to continue . . . 

我试图将各种boost-system库放在setup.py脚本的libraries数组中,但无济于事。

任何帮助将不胜感激!

编辑整个platform_win32.cpp都在这里。

已通过将extra_compile_args=['/EHsc']添加到setup.py脚本来修复编译错误。

最新更新