2015-04-20 53 views
1

我試圖使用Boost.Python將Python集成到我的C++程序中。我已經能夠編譯一些模塊了,但是這個一直給我提供鏈接器錯誤,抱怨boost-system未解決的外部錯誤。LNK1120在構建Python包時引用Boost

我有以下模塊:

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 &)" ([email protected]@@[email protected]@@@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)" ([email protected]@[email protected]@@@[email protected]@[email protected]@[email protected][email protected]@[email protected]@@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

+0

你能否提供'mandala :: platform_win32_t :: get_window_title'函數的簽名? – kvorobiev

+0

@kvorobiev'platform_t :: window_title_type platform_win32_t :: get_window_title()const的 \t { \t \t // TODO:實現這個 \t \t回報的std :: string(); \t}':P –

+0

嗯..你可以添加到你的問題整個'platform_win32_t'代碼? – kvorobiev

回答

1

編譯錯誤通過將extra_compile_args=['/EHsc']添加到setup.py腳本來解決。