[CMake] Problem with Linking CXX shared module

nazia zaman nazia.zaman11 at gmail.com
Thu May 28 01:27:45 EDT 2009


Hi all,
I'm trying to compile a small module using boost python which is like this:

/* File : test.cpp */
#include <boost/python.hpp>
#include <string>
using namespace boost::python;

class Test
{
public:
    std::string test() { return "Test passed."; };
};

BOOST_PYTHON_MODULE(test)
{
    class_<Test>("Test")
        .def("test", &Test::test)
    ;
}


And the CMakeLists.txt is:

# Test for cmake version (not required)
cmake_minimum_required (VERSION 2.6)

# Name of project
project (Test)

# Find library locations using convenient cmake search functions
include (FindBoost)
include (FindPythonLibs)

# Include library include directories (where the header files for python and
boost python are)
include_directories (${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH})

# Add module target (basically tells cmake to build test.cpp as a python
module)
add_library (test MODULE test.cpp)

# Link to boost libraries
target_link_libraries (test
    ${Boost_LIBRARIES}
    ${PYTHON_LIBRARIES}
    )

Running cmake with the command cmake -G "MinGW Makefiles" gives the
following result:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.39.0
-- Found the following Boost libraries:
-- Found PythonLibs: C:/Python25/libs/libpython25.a
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Documents and
Settings/Nazia/Desktop/example_cpp_module

But the 'mingw32-make' command to make the shared module fails with the
following error:

Scanning dependencies of target test
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
Linking CXX shared module libtest.dll
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text+0x11e): undefined reference
to `_imp___ZN5boost6python6detail11init_moduleEPKcPFvvE'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python3defIPFPKcvE
EEvS3_T_[void boost::python::def<char const* (*)()>(char const*, char const*
(*)
())]+0x6e): undefined reference to
`_imp___ZN5boost6python6detail17scope_setattr
_docEPKcRKNS0_3api6objectES3_'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python6detail17mak
e_function_auxIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS4_EEEENS0_3ap
i6objectET_RKT0_RKT1_[boost::python::api::object
boost::python::detail::make_fun
ction_aux<char const* (*)(), boost::python::default_call_policies,
boost::mpl::v
ector1<char const*> >(char const* (*)(),
boost::python::default_call_policies co
nst&, boost::mpl::vector1<char const*> const&)]+0x73): undefined reference
to `_
imp___ZN5boost6python7objects15function_objectERKNS1_11py_functionE'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python7objects21py
_function_impl_baseC2Ev[boost::python::objects::py_function_impl_base::py_functi
on_impl_base()]+0x7): undefined reference to
`_imp___ZTVN5boost6python7objects21
py_function_impl_baseE'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.rdata$_ZTVN5boost6python7objects2
3caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesEN
S_3mpl7vector1IS6_EEEEEE[vtable for
boost::python::objects::caller_py_function_i
mpl<boost::python::detail::caller<char const* (*)(),
boost::python::default_call
_policies, boost::mpl::vector1<char const*> > >]+0x18): undefined reference
to `
boost::python::objects::py_function_impl_base::max_arity() const'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python7objects23ca
ller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3
mpl7vector1IS6_EEEEED1Ev[boost::python::objects::caller_py_function_impl<boost::
python::detail::caller<char const* (*)(),
boost::python::default_call_policies,
boost::mpl::vector1<char const*> > >::~caller_py_function_impl()]+0x16):
undefin
ed reference to `_imp___ZN5boost6python7objects21py_function_impl_baseD2Ev'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python7objects23ca
ller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3
mpl7vector1IS6_EEEEED0Ev[boost::python::objects::caller_py_function_impl<boost::
python::detail::caller<char const* (*)(),
boost::python::default_call_policies,
boost::mpl::vector1<char const*> > >::~caller_py_function_impl()]+0x16):
undefin
ed reference to `_imp___ZN5boost6python7objects21py_function_impl_baseD2Ev'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZNK5boost6python9type_info4
nameEv[boost::python::type_info::name() const]+0x15): undefined reference to
`_i
mp___ZN5boost6python6detail12gcc_demangleEPKc'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZNK5boost6python15to_python
_valueIRKPKcEclES5_[boost::python::to_python_value<char const*
const&>::operator
()(char const* const&) const]+0xf): undefined reference to
`_imp___ZN5boost6pyth
on9converter19do_return_to_pythonEPKc'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python9converter23
expected_pytype_for_argIPKcE10get_pytypeEv[boost::python::converter::expected_py
type_for_arg<char const*>::get_pytype()]+0x24): undefined reference to
`_imp___Z
N5boost6python9converter8registry5queryENS0_9type_infoE'
CMakeFiles\test.dir\test.cpp.obj:test.cpp:(.text$_ZN5boost6python9converter23
expected_pytype_for_argIPKcE10get_pytypeEv[boost::python::converter::expected_py
type_for_arg<char const*>::get_pytype()]+0x3a): undefined reference to
`_imp___Z
NK5boost6python9converter12registration25expected_from_python_typeEv'
collect2: ld returned 1 exit status
mingw32-make[2]: *** [libtest.dll] Error 1
mingw32-make[1]: *** [CMakeFiles/test.dir/all] Error 2
mingw32-make: *** [all] Error 2

I've no idea how to fix this and really need your help. Can anyone help me
out?

Regards,
Nazia Zaman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090528/63deb61e/attachment-0001.htm>


More information about the CMake mailing list