[C++-sig] Re: linking problems with gcc and embedded python

David Abrahams dave at boost-consulting.com
Mon May 26 15:48:17 CEST 2003


"Paul Querna" <chip at cyan.com> writes:

> First off, this code works fine in Windows using VC++ v6. (the
> pinnacle of all compilers! (hehe))

<g>

> This error reproduces in gcc 3.0.2(redhat 7.2) and 3.2.2(redhat
> 9.0).
>
> We are using boost 1.29.0. Upgrading to the latest CVS would be
> possible if it will fix this, but we would prefer not to have to go
> this route.(pain, suffering, death... etc)

I think you overestimate the pain.  Almost everything "just works
better" in 1.30.0.

> We are in the process of adding an embedded python interpreter to
> one of our server programs.
>
> We have built a boost python shared object that we dynamicly link to
> in our servers.  It seems to work fine for other things.
>
> Here are the linking errors we get: (be prepared... its ugly..)


In the future, please pass your ugly GCC error messages through Leor
Zolman's wonderful STLFilt formatting engine (www.bdsoft.com), to get:

../../../../UnixProjects/Plasma/Apps/plNetGameServer/plNetGameServer.dbg.lib.a(pyPythonMsg.dbg.o)(
        .gnu.linkonce.t.
        _ZN5boost6python6detail17make_function_auxIM11pyPythonMsgFSsvENS0_21default_call_policiesENS1_16args_from_python
        ENS_3mpl5list2ISsRS3_EENS8_5int_cILi0EEEEENS0_3api6objectET_RKT0_RKT1_RKT2_RKSt4pairIPKNS1_7keywordEST_ET3_+
        0x4d):
In function `boost::python::api::object
boost::python::detail::make_function_aux<
    basic_string<
        char,
        char_traits<char> 
    > (pyPythonMsg::*)(),
    boost::python::default_call_policies, 
    boost::python::detail::args_from_python,
    boost::mpl::list2<
            basic_string<
                char, char_traits<char>,
                allocator<char> >, 
            pyPythonMsg&
    >, 
    boost::mpl::int_c<(int)0>
>(
    string
    (pyPythonMsg::*)(), 
    boost::python::default_call_policies const&,
    boost::python::detail::args_from_python const&,
    boost::mpl::list2<
            basic_string<
                char, char_traits<char>,
                allocator<char> 
            >, 
    pyPythonMsg&> const&,
    pair<
            boost::python::detail::keyword const*,
            boost::python::detail::keyword const*
    > const&, 
    boost::mpl::int_c<(int)0>
)':

../../../../../StaticSDKs/XPlatform/boost_1_29_0/boost/function/function_base.hpp:246:
undefined reference to
`boost::python::objects::function_object(
     boost::function2<
         _object*, _object*,_object*
     > const&, 
     unsigned,
     pair<
          boost::python::detail::keyword const*,
          boost::python::detail::keyword const*
     > const&
)'

Looks to me like you're not linking to the Boost.Python shared
library.  Thats where that function is located.

> sniplet of part of the offending code:
>
> void pyPythonMsg::PythonModDef()
> {
>         class_<pyPythonMsg>("ptPythonMsg", init<>())
>                 .def("getContents",&pyPythonMsg::GetMsgContents)
>                 .def("setContents",&pyPythonMsg::SetMsgContents)
>                 .def("getSenderID",&pyPythonMsg::GetSenderID)
>                
> .def("getKey",&pyPythonMsg::GetKey,return_value_policy<manage_new_object>())
>                 .def("setKey",&pyPythonMsg::SetKey)
>                 .def("send",&pyPythonMsg::SendMessage)
>         ;
>         pyKey::PythonModDef();
> }
>
> If the defs are commented out, we do not get these linking errors.  

That's rather surprising.  These defs shouldn't be using that
function, since they don't expose any keyword arguments.

> The same code works great under windows and VC++. The code without
> the embedded python interpreter also works under both Windows and
> Linux.
>
> I have been looking over these errors, but I can't seem to find anything
> obvious that would be causing them.  

Normally I'd say it's not in your source code; they're link errors so
it's in the way you're assembling your application/module.

> For example, we aren't missing other boost python functions, the
> linker seems to find them, but somthing about these defs are causing
> the linker to not see the boost functions. We have tried quote a few
> variations, recompiled boost a couple times, linked to debug
> /nondebug.. etc., but can't seem to find anything that is causing
> this.

> Because of the nature of this server, I cannot release a full copy of its
> source for outside developers to test it. Sorry about that.  
>
> Any pointers or possible solutions, no matter how faint of a chance, would be
> greatly appreciated.

Aside from updating your Boost installation, which I highly recommend
anyway, you could think about explicitly specifying keywords in one of
those .def() calls so that it actually *tries* hard to get ahold of
that function and causes it to stay linked-in to the executable image.

See http://www.boost.org/libs/python/doc/v2/args.html#args-spec

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list