Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-02-12 08:19:47


----- Mensaje original -----
De: Robert Ramey <ramey_at_[hidden]>
Fecha: Sábado, Febrero 11, 2006 10:26 pm
Asunto: Re: [boost] [serialization] serialization/nvp.hppmakes
        autolink kickin

> JOAQUIN LOPEZ MU?Z wrote:
[...]
> >
> > #include <boost/serialization/nvp.hpp>
> > // rest of serialization headers which must not trigger autolink
> > #include <...>
> >
> > // declare some function of the serialization
> > // lib (which shouldn't be linked)
> >
> > int some_f();
> >
> > int main()
> > {
> > // use the function in whatever manner
> > int x=some_f();
> > }
> >
> > Now, if autolink does not get activated, the
> > program should fail as some_f is not linked in.
> > So, in your Jamfile just mark this as a link-fail:
> >
> > [ link-fail auto_link_not_invoked.cpp ]
>
>
> I didn't know about link-fail - but I'm still missing something here.
>
> If I refer to a function that is declared in one of my headers - then
> auto-linking will be triggered. It doesn't matter whether this
> reference occurs by taking its address or by invoking it by name.
>

I'm afraid I don't agree here --linkers are not that smart,
in fact autolinking is triggered by the appropriate
#pragmas only, when you include some header that have those.
It doesn't have anything to do with whether the symbols of
the lib are used or not.

What I propose is that you declare some symbol of the lib
*without* using the associate header, which would
trigger autolinking. For instance (I haven't actually
tested this):

// all the serialization headers which mustn't trigger autolink
#include <....>

// unregister_void_casts is defined by the serialization lib.

namespace boost {
namespace serialization {

class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info;

void BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY())
unregister_void_casts(extended_type_info *eti);

} /* serialization */
} /* boost */

int main()
{
  using namespace boost::serialization;

  typedef void BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY())
  (* unregister_void_casts_type)(extended_type_info *);

  unregister_void_casts_type pf=&unregister_void_casts;

  return 0;
}

Only when the serialization lib is linked in can this
program build OK --so, when autolinking has not been
spuriously activated the expected outcome is link failure.

> Now I "think" bjam sets up a path to the directory that contains
> my pre-built boost libraries - so the reference will be found
> and and the program will link. Its not clear to me that I can
> suppress this and guarentee that the link will fail.
>

My comment above applies: autolinking is a #pragma thing,
nothing to do with linker finding dangling symbol references
--unless I'm grossly mistaken :)

Best regards,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk