python - 构建引用 Boost 的 Python 包时出现 LNK1120

标签 python c++ boost 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',
        '..\ext\glm-0.9.4.4',
        '..\ext\glew-1.10.0\include',
        '..\ext\glfw-3.0.1.bin.WIN32\include'],
        library_dirs=['C:\\boost_1_55_0\stage\lib',
        '..\ext\glfw-3.0.1.bin.WIN32\lib-msvc110',
        '..\ext\glew-1.10.0\lib\Release\Win32'],
        libraries=['glfw3', 'glew32', 'opengl32', 'user32', 'gdi32']
        )
    ])

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

running build
running build_ext
building 'platform' extension
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\boost_1_55_0 -I..\ext\glm-0.9.4.4 -I..\ext\glew-1.10.0\include -I..\ext\glfw-3.0.1.bin.WIN32\include -IC:\Python27\include -IC:\Python27\PC /Tp../mandala/platform_win32.cpp /Fobuild\temp.win32-2.7\Release\../mandala/platform_win32.obj
platform_win32.cpp
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xlocale(337) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
c:\python27\include\pymath.h(22) : warning C4273: 'round' : inconsistent dll linkage
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(516) : see previous definition of 'round'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\boost_1_55_0\stage\lib /LIBPATH:..\ext\glfw-3.0.1.bin.WIN32\lib-msvc110 /LIBPATH:..\ext\glew-1.10.0\lib\Release\Win32 /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild glfw3.lib glew32.lib opengl32.lib user32.lib gdi32.lib /EXPORT:initplatform build\temp.win32-2.7\Release\../mandala/platform_win32.obj /OUT:build\lib.win32-2.7\platform.pyd /IMPLIB:build\temp.win32-2.7\Release\../mandala\platform.lib /MANIFESTFILE:build\temp.win32-2.7\Release\../mandala\platform.pyd.manifest
   Creating library build\temp.win32-2.7\Release\../mandala\platform.lib and object build\temp.win32-2.7\Release\../mandala\platform.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)
build\lib.win32-2.7\platform.pyd : fatal error LNK1120: 1 unresolved externals
Press any key to continue . . . 

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

如有任何帮助,我们将不胜感激!

编辑 platform_win32.cpp 的整体是 here .

最佳答案

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

关于python - 构建引用 Boost 的 Python 包时出现 LNK1120,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757926/

相关文章:

python - 测量音频 "loudness": RMS vs. LUFS

python - 使用python查找子矩阵中不同元素数量的最佳方法

python - Django URLConf 不匹配有效的正则表达式

c++ - boost::heap::priority_queue 与 std::priority_queue 的比较器

python - 使用单个命令从字典列表中获取某个键的所有值

android - 带有 pthread 析构函数的 c++ thread_local 析构函数

c++ - 为什么这些具有外部链接的名称不表示同一实体?

c++ - 初始化 std::unique_ptr 作为原始数组指针初始化

c++ - 寻找已排序的容器,其中指向元素的指针在添加/删除时不会改变

相当于 Boost has_dereference 的 C++11 std