libdatachannel icon indicating copy to clipboard operation
libdatachannel copied to clipboard

Diagnostic when linking with LTO: `warning: 'send' violates the C++ One Definition Rule`

Open edmonds opened this issue 1 year ago • 2 comments

Hi,

I'm building a project using the meson build system with the libdatachannel dependency supplied as a meson-wrapped CMake subproject and linking libdatachannel statically into the project. I get the following diagnostic from G++ when linking the project with LTO mode enabled:

../subprojects/libdatachannel/include/rtc/track.hpp:37:14: warning: 'send' violates the C++ One Definition Rule [-Wodr]
   37 |         bool send(message_variant data) override;
      |              ^
../subprojects/libdatachannel/src/track.cpp:33:6: note: type mismatch in parameter 1
   33 | bool Track::send(message_variant data) { return impl()->outgoing(make_message(std::move(data))); }
      |      ^
../subprojects/libdatachannel/src/track.cpp:33:6: note: type 'struct message_variant' itself violates the C++ One Definition Rule
../subprojects/libdatachannel/src/track.cpp:33:6: note: 'send' was previously declared here
../subprojects/libdatachannel/include/rtc/datachannel.hpp:43:14: warning: 'send' violates the C++ One Definition Rule [-Wodr]
   43 |         bool send(message_variant data) override;
      |              ^
../subprojects/libdatachannel/src/datachannel.cpp:49:6: note: type mismatch in parameter 1
   49 | bool DataChannel::send(message_variant data) {
      |      ^
../subprojects/libdatachannel/src/datachannel.cpp:49:6: note: type 'struct message_variant' itself violates the C++ One Definition Rule
../subprojects/libdatachannel/src/datachannel.cpp:49:6: note: 'send' was previously declared here
../subprojects/libdatachannel/include/rtc/websocket.hpp:62:14: warning: 'send' violates the C++ One Definition Rule [-Wodr]
   62 |         bool send(const message_variant data) override;
      |              ^
../subprojects/libdatachannel/src/websocket.cpp:52:6: note: type mismatch in parameter 1
   52 | bool WebSocket::send(message_variant data) {
      |      ^
../subprojects/libdatachannel/src/websocket.cpp:52:6: note: type 'struct message_variant' itself violates the C++ One Definition Rule
../subprojects/libdatachannel/src/websocket.cpp:52:6: note: 'send' was previously declared here

Not sure how serious this is, or if the answer is just "don't link libdatachannel in LTO mode".

I put together a reproducible test case here:

https://github.com/edmonds/meson-subproject-example-libdatachannel

Also attached is a full build log of the test case when running in a clean Debian unstable container. build.txt

Thanks!

edmonds avatar Dec 21 '23 21:12 edmonds

This kind of issue could happen with LTO because headers appear different between library compilation and application compilation. For instance, some defines could be different between the library build and the meson application build.

paullouisageneau avatar Jan 07 '24 21:01 paullouisageneau

OK, I'll have to do some more digging to see exactly what defines differ between the library build and the application build in this case, but I guess if this doesn't seem to be a bug in libdatachannel you can close this issue. Thanks!

edmonds avatar Jan 08 '24 08:01 edmonds