Hello,
We are using ASIO (header file version) in our project. It's been working
quite nice, thanks for the great library!
I've just found a problem in using the latest version with clang++, though.
It complains about 'multiple definition' errors at link time, like this:
Clang/build/src/lib/asiolink/../../../ext/asio/asio/ip/detail/endpoint.hpp:110: multiple definition of `asio::ip::detail::operator<(asio::ip::detail::endpoint const&, asio::ip::detail::endpoint const&)'
.libs/libasiolink_la-interval_timer.o(.text+0x34a0):/usr/home/jreed/builder/work/BIND10/20110419071501-FreeBSD8-i386-Clang/build/src/lib/asiolink/../../../ext/asio/asio/ip/detail/endpoint.hpp:110: first defined here
I checked the ASIO code and found that it declares some functions and
methods as 'inline', while providing their definitions without
explicitly saying inline (again). For example, in
ip/detail/endpoint.hpp, it declares:
ASIO_DECL friend bool operator<(
const endpoint& e1, const endpoint& e2);
while in ip/detail/impl/endpoint.ipp (which endpoint.hpp includes in
the header only mode) says:
bool operator<(const endpoint& e1, const endpoint& e2)
{
if (e1.address() < e2.address())
...
Apparently clang++ considers the definition not (necessarily) inline,
and produces multiple copies of it in all application sources that
(indirectly) include endpoint.hpp, resulting in the above linker
error. (FWIW g++ doesn't show this behavior.)
I don't know whether the clang++ behavior is okay in terms of the
language specification, but it seems to me it doesn't do any harm if
the ASIO definitions have the "redundant" inline keyword (using the
ASIO_DECL macro).
For your reference, I'm attaching a diff file that makes build succeed
for us (there may be some more cases that would need the same change).
I'd very much appreciate if you could consider introducing the remedy.
Thanks,
sample patch to fix the problem