1

I am trying to compile a Python library (CEGUI can build Python modules, its editor relies on that) that needs to link against boost-python. So I built boost, with --with-python and it built just fine.

However, as soon as the .pyd is linked, I get undefined references:

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

My first assumption was that it does not link against boost-python, but the link.txt inside the CMake folders shows this:

"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

So boost-python is linked against. I am unsure what could be the problem here. Boost? CEGUI? MinGW?...

TheSHEEEP
  • 2,961
  • 2
  • 31
  • 57
  • Can you link against boost python dynamically instead of statically? – mockinterface Feb 24 '14 at 09:19
  • Interesting question. I will try that. How did you get the idea? Are there known problems when linking boost_python statically? – TheSHEEEP Feb 24 '14 at 09:24
  • Let's see if it works, it's just a hunch. Also are you sure about the --whole-archive which get immediately turned off? What generated this particular arrangement of switches? Possible the static python library should still fall under the auspice of --whole-archive, I've never seen such particular arrangement. – mockinterface Feb 24 '14 at 09:32
  • This is the CMake project of CEGUI. So I'm not actually sure about anything in there ;) – TheSHEEEP Feb 24 '14 at 09:33
  • Hmmm, I just noticed that I do not have a shared version of boost_python. It throws lots of undefined references when trying to build the shared version. – TheSHEEEP Feb 24 '14 at 09:49
  • Are you building with: `--with-boost_python` ? What is the g++ version? If it is too old you might not be able to build. – mockinterface Feb 24 '14 at 09:55
  • Yes I build with "--with-python", the G++ version is the latest from MinGW. 4.8.1 I think. – TheSHEEEP Feb 24 '14 at 09:59
  • I posted a request on the boost.build mailing list. This somehow seems to be a problem with the build system not linking Python correctly. – TheSHEEEP Feb 24 '14 at 10:19
  • Good luck :) You'll need it with the combination of mingw, cmake, cegui, python and boost python. – mockinterface Feb 24 '14 at 10:45

1 Answers1

1

Turns out, the problem was that I was using the 64bit version of Python. I downloaded it months ago and just forgot about that little fact.

Now, MinGW can only compile and use 32 bit libraries, not mix in 64 bit. This is what led to boost-python not compiling correctly (it's a wonder it did compile at all) and thus having undefined references when linked against.

Downloading the 32bit version of Python and recompiling boost solved the problems.

TheSHEEEP
  • 2,961
  • 2
  • 31
  • 57