Linkage errors when building a SIMPLE Python module using Boost Python library

Viewed 17

I'm following this example to build a super simple "Hello World" Python module:

https://gist.github.com/ndevenish/ff771feb6817f7debfa728386110f567

I'm using CLion IDE on Windows. I get a number of linker errors and have been unable to track down the problem after spending hours on this. The g++ command that fails is:

g++.exe -O3 -DNDEBUG -shared -o hello_ext.dll hello_ext.cpp.obj -LC:/tools/mambaforge/pkgs/boost-1.80.0-py310h220cb41_1/Library/lib -LC:/tools/mambaforge/libs -lboost_python310  -lpython310 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

And the error output is:

ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text+0x79): undefined reference to `__imp__ZN5boost6python7objects15function_objectERKNS1_11py_functionE'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text+0x9c): undefined reference to `__imp__ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text+0x128): undefined reference to `__imp__ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZNK5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEE9signatureEv[_ZNK5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEE9signatureEv]+0x7b): undefined reference to `__imp__ZN5boost6python6detail12gcc_demangleEPKc'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZNK5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEE9signatureEv[_ZNK5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEE9signatureEv]+0xcf): undefined reference to `__imp__ZN5boost6python6detail12gcc_demangleEPKc'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x1c): undefined reference to `__imp__ZN5boost6python9converter8registry5queryENS0_9type_infoE'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x2f): undefined reference to `__imp__ZNK5boost6python9converter12registration25expected_from_python_typeEv'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEclEP7_objectSG_[_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEclEP7_objectSG_]+0x11): undefined reference to `__imp__ZN5boost6python9converter19do_return_to_pythonEPKc'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED1Ev[_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED1Ev]+0xd): undefined reference to `__imp__ZN5boost6python7objects21py_function_impl_baseD2Ev'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.text$_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED0Ev[_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEED0Ev]+0x15): undefined reference to `__imp__ZN5boost6python7objects21py_function_impl_baseD2Ev'
ld.exe: hello_ext.cpp.obj:hello_ext.cpp:(.rdata$_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
collect2.exe: error: ld returned 1 exit status

(I have removed full paths from the above to make the command and output more readable.)

If I try to create a static library, it works, but of course then I cannot use it as a Python module.

I'm at my wits end as to what the issue is. Googling the specific linker errors did not provide useful answers. Can anyone help please?

0 Answers
Related