linker issues when building mediasoup-broadcaster-demo

I’m trying to build mediasoup-broadcaster-demo and run into linker errors. I’ve a working libwebrtc m74 build.

[ 80%] Linking CXX executable broadcaster
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cricket::ToStringIfSet<bool>(char const*, absl::optional<bool> const&)':
Broadcaster.cpp:(.text+0x321f): undefined reference to `rtc::ToString[abi:cxx11](bool)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cricket::ToStringIfSet<int>(char const*, absl::optional<int> const&)':
Broadcaster.cpp:(.text+0x338f): undefined reference to `rtc::ToString[abi:cxx11](int)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o: In function `mediasoupclient::PeerConnection::RTCStatsCollectorCallback::OnStatsDelivered(rtc::scoped_refptr<webrtc::RTCStatsReport const> const&)':
Broadcaster.cpp:(.text._ZN15mediasoupclient14PeerConnection25RTCStatsCollectorCallback16OnStatsDeliveredERKN3rtc13scoped_refptrIKN6webrtc14RTCStatsReportEEE[_ZN15mediasoupclient14PeerConnection25RTCStatsCollectorCallback16OnStatsDeliveredERKN3rtc13scoped_refptrIKN6webrtc14RTCStatsReportEEE]+0x4a): undefined reference to `webrtc::RTCStatsReport::ToJson[abi:cxx11]() const'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTVN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE[_ZTVN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE]+0x40): undefined reference to `webrtc::CreateSessionDescriptionObserver::OnFailure(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTVN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE[_ZTVN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE]+0x40): undefined reference to `webrtc::SetSessionDescriptionObserver::OnFailure(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::CreateSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::SetSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/main.cpp.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cricket::ToStringIfSet<bool>(char const*, absl::optional<bool> const&)':
...

This looks to me like a gcc/clang stdlib issue. I get this error both with a libwebrtc build with clang and gcc. Switching to clang for the mediasoup-broadcaster-demo build gives me slightly different errors

[ 80%] Linking CXX executable broadcaster
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o: In function `mediasoupclient::PeerConnection::RTCStatsCollectorCallback::OnStatsDelivered(rtc::scoped_refptr<webrtc::RTCStatsReport const> const&)':
Broadcaster.cpp:(.text._ZN15mediasoupclient14PeerConnection25RTCStatsCollectorCallback16OnStatsDeliveredERKN3rtc13scoped_refptrIKN6webrtc14RTCStatsReportEEE[_ZN15mediasoupclient14PeerConnection25RTCStatsCollectorCallback16OnStatsDeliveredERKN3rtc13scoped_refptrIKN6webrtc14RTCStatsReportEEE]+0x2f): undefined reference to `webrtc::RTCStatsReport::ToJson[abi:cxx11]() const'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.rodata._ZTVN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE[_ZTVN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE]+0x40): undefined reference to `webrtc::SetSessionDescriptionObserver::OnFailure(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.rodata._ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::SetSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.rodata._ZTVN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE[_ZTVN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE]+0x40): undefined reference to `webrtc::CreateSessionDescriptionObserver::OnFailure(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.rodata._ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::CreateSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/peerConnectionUtils.cpp.o: In function `createPeerConnectionFactory()':
peerConnectionUtils.cpp:(.text+0x430): undefined reference to `rtc::Thread::SetName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void const*)'
...

Any hints of how to complete this build successfully?

Thanks!
Robert

I missed

Build libwebrtc with the ‘use_custom_libcxx=false’ gn gen argument to force it use of the system libstdc++.

at mediasoup :: Installation

So this helped a bit but still linker errors…

[ 80%] Linking CXX executable broadcaster
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection32CreateSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::CreateSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/Broadcaster.cpp.o:(.data.rel.ro._ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE[_ZTIN15mediasoupclient14PeerConnection29SetSessionDescriptionObserverE]+0x10): undefined reference to `typeinfo for webrtc::SetSessionDescriptionObserver'
CMakeFiles/broadcaster.dir/src/peerConnectionUtils.cpp.o:(.data.rel.ro._ZTI19CapturerTrackSource[_ZTI19CapturerTrackSource]+0x10): undefined reference to `typeinfo for webrtc::VideoTrackSource'
CMakeFiles/broadcaster.dir/src/peerConnectionUtils.cpp.o:(.data.rel.ro._ZTIN6webrtc25VideoTrackSourceInterfaceE[_ZTIN6webrtc25VideoTrackSourceInterfaceE]+0x18): undefined reference to `typeinfo for webrtc::MediaSourceInterface'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_alsa_linux.o): In function `webrtc::AudioDeviceLinuxALSA::Init()':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_alsa_linux.cc:158: undefined reference to `XOpenDisplay'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_alsa_linux.o): In function `webrtc::AudioDeviceLinuxALSA::Terminate()':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_alsa_linux.cc:202: undefined reference to `XCloseDisplay'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_alsa_linux.o): In function `webrtc::AudioDeviceLinuxALSA::KeyPressed() const':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_alsa_linux.cc:1640: undefined reference to `XQueryKeymap'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_pulse_linux.o): In function `webrtc::AudioDeviceLinuxPulse::Init()':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_pulse_linux.cc:154: undefined reference to `XOpenDisplay'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_pulse_linux.o): In function `webrtc::AudioDeviceLinuxPulse::Terminate()':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_pulse_linux.cc:213: undefined reference to `XCloseDisplay'
/path/to/webrtc-google-3/src/out/gcc/obj/libwebrtc.a(audio_device_pulse_linux.o): In function `webrtc::AudioDeviceLinuxPulse::KeyPressed() const':
/path/to/webrtc-google-3/src/out/gcc/../../modules/audio_device/linux/audio_device_pulse_linux.cc:2278: undefined reference to `XQueryKeymap'
collect2: error: ld returned 1 exit status

Any ideas what that could be?

Alright, using gcc with $ gn gen out/mybuild-m74 --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true rtc_enable_protobuf=false use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_ozone=true' (as mentioned in the documentation) worked. Just needed some rubber ducking.

Just take into account that you did not even tell which OS you are running.

BTW: is that working command the same as the one exposed in the documentation?

I’m using Ubuntu 18.04. And yes, the build command for libwebrtc is from the documentation.

So the doc is fine, right? :slight_smile:

Note however that building libwebrtc is out of the scope of libmediasoupclient, we just provide some hints but those may need to change depending on libwebrtc version or OS.

Yes, the docs are good and I didn’t intend to suggest otherwise. I’ve added the build command above as it is the direct answer to my question. I missed the build section when I first started out, my apologies for that. Thanks for putting it out there!

Thanks. If anyway you see something that can be improved in the documentation, don’t hesitate to tell it.

2 Likes

Looks like I have the same issues on Ubuntu 20.04.
I have built WebRTC of version branch-heads/4606 with all the arguments described above and have all these linker errors.
Should any specific linker options be added or something?