mutiple template definitions when linking

Bug #601886 reported by Richard Forrest
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fast/CGI
New
Undecided
Unassigned

Bug Description

Compiler: gcc-4.3.2
Platform: Ubuntu linux
Boost version: 1.43

When linking two separately compiled object files that both include <boost/fcgi.hpp>, the link fails with:

MenuModule.o:/usr/include/boost/cgi/fcgi/client.hpp:157: first defined here
Menu.o: In function `boost::cgi::common::basic_client<boost::cgi::common::tags::fcgi>::handle_write(unsigned int, boost::system::error_code&)':
/usr/include/boost/cgi/fcgi/client.hpp:157: multiple definition of `boost::cgi::common::basic_client<boost::cgi::common::tags::fcgi>::handle_write(unsigned int, boost::system::error_code&)'

etc....

The problem seems to be that fully specialized versions of template functions should be declared as inline. Not doing so causes a version to exist in each compilation unit.

I inlined the ones that seemed to be causing the linking problem.

e.g. in boost/cgi/fcgi/client.hpp

  template<>
inline <--------------------- Added by me!
  void
  basic_client<
      ::BOOST_CGI_NAMESPACE::common::tags::fcgi
  >::handle_write(std::size_t bytes_transferred, boost::system::error_code& ec)

That seemed to fix it.

There are a few more in that file which I also needed to inline. Probably there are others in other files but they have not caused me problems.

Best regards, Richard

P.S. This is a really cool library. Thanks for all your hard work.

Revision history for this message
Darren Garvey (darren-garvey) wrote : Re: [Bug 601886] [NEW] mutiple template definitions when linking

Hi Richard,

Thanks for the report.

The test suite is currently missing an automated test for multiple
translation units, which is why this was missed. I tested this within the
last couple of months, so I think this should be the only broken class, but
I'll apply this fix and add a test case for it this evening / or tomorrow.

Cheers,
Darren

P.S. The launchpad site isn't kept up to date - http://cgi.sf.net is the
main site for the library these days!

On 5 July 2010 13:32, Richard Forrest <email address hidden> wrote:

> Public bug reported:
>
>
> Compiler: gcc-4.3.2
> Platform: Ubuntu linux
> Boost version: 1.43
>
>
> When linking two separately compiled object files that both include
> <boost/fcgi.hpp>, the link fails with:
>
> MenuModule.o:/usr/include/boost/cgi/fcgi/client.hpp:157: first defined here
> Menu.o: In function
> `boost::cgi::common::basic_client<boost::cgi::common::tags::fcgi>::handle_write(unsigned
> int, boost::system::error_code&)':
> /usr/include/boost/cgi/fcgi/client.hpp:157: multiple definition of
> `boost::cgi::common::basic_client<boost::cgi::common::tags::fcgi>::handle_write(unsigned
> int, boost::system::error_code&)'
>
> etc....
>
> The problem seems to be that fully specialized versions of template
> functions should be declared as inline. Not doing so causes a version to
> exist in each compilation unit.
>
> I inlined the ones that seemed to be causing the linking problem.
>
> e.g. in boost/cgi/fcgi/client.hpp
>
> template<>
> inline <--------------------- Added by me!
> void
> basic_client<
> ::BOOST_CGI_NAMESPACE::common::tags::fcgi
> >::handle_write(std::size_t bytes_transferred, boost::system::error_code&
> ec)
>
> That seemed to fix it.
>
> There are a few more in that file which I also needed to inline.
> Probably there are others in other files but they have not caused me
> problems.
>
> Best regards, Richard
>
> P.S. This is a really cool library. Thanks for all your hard work.
>
> ** Affects: cgi
> Importance: Undecided
> Status: New
>
> --
> mutiple template definitions when linking
> https://bugs.launchpad.net/bugs/601886
> You received this bug notification because you are the registrant for
> Fast/CGI.
>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.