python - 链接到 boost-python 会在 PyCEGUI 中产生 undefined reference

标签 python c++ boost boost-python cegui

我正在尝试编译 Python library (CEGUI 可以构建 Python 模块,它的编辑器依赖于它)需要链接到 boost-python。所以我用 --with-python 构建了 boost,它构建得很好。

但是,一旦链接了 .pyd,我就会得到 undefined reference :

Linking CXX shared module ..\..\..\..\..\bin\PyCEGUI.pyd
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x97): undefined reference to `_imp___ZN5boost6python7objects10class_baseC2EPKcjPKNS0_9type_infoES4_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x9c): undefined reference to `_imp___ZN5boost6python9converter8registry6insertEPFPvP7_objectEPFvS5_PNS1_30rvalue_from_python_stage1_dataEENS0_9type_infoEPFPK11_typeobjectvE
'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0xcc): undefined reference to `_imp___ZN5boost6python7objects23register_dynamic_id_auxENS0_9type_infoEPFSt4pairIPvS2_ES4_E'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0xf4): undefined reference to `_imp___ZN5boost6python7objects8add_castENS0_9type_infoES2_PFPvS3_Eb'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1cd): undefined reference to `_imp___ZN5boost6python7objects17copy_class_objectERKNS0_9type_infoES4_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x20d): undefined reference to `_imp___ZN5boost6python9converter8registry6insertEPFP7_objectPKvENS0_9type_infoEPFPK11_typeobjectvE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x245): undefined reference to `_imp___ZN5boost6python7objects10class_base17set_instance_sizeEj'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x281): undefined reference to `_imp___ZN5boost6python7objects15function_objectERKNS1_11py_functionERKSt4pairIPKNS0_6detail7keywordES9_E'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x2f2): undefined reference to `_imp___ZN5boost6python7objects16add_to_namespaceERKNS0_3api6objectEPKcS5_S7_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x348): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x4d1): undefined reference to `_imp___ZN5boost6python9converter8registry9push_backEPFPvP7_objectEPFvS5_PNS1_30rvalue_from_python_stage1_dataEENS0_9type_infoEPFPK11_typeobjectvE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x636): undefined reference to `_imp___ZN5boost6python7objects16add_to_namespaceERKNS0_3api6objectEPKcS5_'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1246): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):AbsoluteDim.pypp.cpp:(.text+0x1267): undefined reference to `_imp___ZN5boost6python6detail13current_scopeE'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: CMakeFiles\PyCEGUI.dir/objects.a(AbsoluteDim.pypp.cpp.obj):
bad reloc address 0x2 in section `.text$_ZN5boost6detail15sp_counted_baseD1Ev[__ZN5boost6detail15sp_counted_baseD1Ev]'
collect2.exe: error: ld returned 1 exit status
cegui\src\ScriptModules\Python\bindings\CMakeFiles\PyCEGUI.dir\build.make:6698: recipe for target 'bin/PyCEGUI.pyd' failed
mingw32-make[2]: *** [bin/PyCEGUI.pyd] Error 1
CMakeFiles\Makefile2:726: recipe for target 'cegui/src/ScriptModules/Python/bindings/CMakeFiles/PyCEGUI.dir/all' failed
mingw32-make[1]: *** [cegui/src/ScriptModules/Python/bindings/CMakeFiles/PyCEGUI.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

我的第一个假设是它没有链接到 boost-python,但是 CMake 文件夹中的 link.txt 显示:

"C:\Coding\CMake 2.8\bin\cmake.exe" -E remove -f CMakeFiles\PyCEGUI.dir/objects.a C:\MinGW\bin\ar.exe cr CMakeFiles\PyCEGUI.dir/objects.a @CMakeFiles\PyCEGUI.dir\objects1.rsp C:\MinGW\bin\g++.exe -shared -o ..........\bin\PyCEGUI.pyd -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\PyCEGUI.dir/objects.a -Wl,--no-whole-archive ..........\lib\libCEGUIBase-0.dll.a C:\Coding\boost_1_53_0\lib\libboost_python-mgw48-mt-1_53.a C:\Python27\libs\python27.lib C:\Coding\CEGUI\cegui\dependencies\lib\dynamic\libfreetype.dll.a C:\Coding\CEGUI\cegui\dependencies\lib\dynamic\libpcre.dll.a -lwinmm -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

所以 boost-python 被链接了。 我不确定这里可能是什么问题。 boost ? CEGUI? MinGW?...

最佳答案

事实证明,问题出在我使用的是 64 位版本的 Python。我几个月前下载了它,只是忘记了这个小事实。

现在,MinGW只能编译使用32位库,不能混入64位。这就是导致 boost-python 无法正确编译的原因(它确实编译了,这真是一个奇迹),因此在链接时具有 undefined reference 。

下载32位版本的Python,重新编译boost,问题解决。

关于python - 链接到 boost-python 会在 PyCEGUI 中产生 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21952618/

相关文章:

python - PyQt4 QTimer 不起作用

python - 如何在 BeautifulSoup 中保持 Django 模板代码的有效性

c++ - 数组和引用传递

c++ - 编译Boost::Python时出现问题

c++ - 我们应该通过引用还是按值传递 shared_ptr ?

python - GAE/Python - 将请求从 Controller 传递到模型的最佳方式是什么?

python - 遍历文件结构Python的最有效方法

c++ - 使用基类的 ADL swap

c++ - 导致数千个错误的文件 (C++)

c++ - 使 boost::fusion::result_of::as_set<> 's instance doesn' t 调用其元素的构造函数