Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Error linking libwebrtc.a with C++ on linux

578 views
Skip to first unread message

Yugander Krishan Singh

unread,
Jul 16, 2020, 6:00:29 PM7/16/20
to discuss-webrtc
I have built webrtc for linux and getting `libwebrtc.a` using

    gn gen out/Default --args=is_debug=false rtc_use_h264=true target_cpu="x64" target_os="linux" clang_use_chrome_plugins=false use_ghash=false symbol_level=2 use_custom_libcxx=false is_component_ffmpeg=true ffmpeg_branding="Chrome" rtc_include_tests=false rtc_build_examples=true rtc_build_tools=false use_rtti=true rtc_enable_protobuf=false rtc_use_h264=true rtc_link_pipewire=true proprietary_codecs=true

and

    ninja -C . webrtc \
    peerconnection_client


but when I am trying to link the static webrtc with my c++ project I am getting following 4 linker errors:

 

    1. test.cpp:(.text._ZN10H264BypassedEncoderC2ERKN7cricket10VideoCodecERNS_14DCVAgentClientE+0x191):
        undefined reference to  
        `absl::EqualsIgnoreCase(std::basic_string_view<char,  
        std::char_traits<char> >, std::basic_string_view<char,  
        std::char_traits<char> >)'
     2. CMakeFiles/webRTCserver.dir/src/audio/testEncoder.cpp.o:(.data.rel.ro._ZTVN10testEncoderE[_ZTVN10testEncoderE]+0xb8):
        undefined reference to
        `webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int,
        std::optional<long>)'
     3. testDecoderFactory.cpp/testEncoderFactory.cpp:(.text._ZN10testEncoderFactory20GetSupportedEncodersEv+0x20b): undefined reference to
        `webrtc::SdpAudioFormat::SdpAudioFormat(std::basic_string_view<char,
        std::char_traits<char> >, int, unsigned long,
        std::map<std::__cxx11::basic_string<char, std::char_traits<char>,
        std::allocator<char> >, std::__cxx11::basic_string<char,
        std::char_traits<char>, std::allocator<char> >,
        std::less<std::__cxx11::basic_string<char, std::char_traits<char>,
        std::allocator<char> > >,
        std::allocator<std::pair<std::__cxx11::basic_string<char,
        std::char_traits<char>, std::allocator<char> > const,
        std::__cxx11::basic_string<char, std::char_traits<char>,
        std::allocator<char> > > > >&&)'
     4. H264BypassedEncoder.cpp.o:(.data.rel.ro._ZTVN10H264BypassedEncoderE[_ZTVN10H264BypassedEncoderE]+0x20):
        undefined reference to
        `webrtc::VideoEncoder::SetFecControllerOverride(webrtc::FecControllerOverride*)'


When I look for symbols in libwebrtc.a like error 2 as shown below:

    nm --demangle libwebrtc.a | grep -i webrtc::AudioEncoder::OnReceivedUplinkBandwidth

I get the following output:

    0000000000000000 T webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)
                     U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)

Now I am not sure why nm shows the output the way it does. But then using `ar -d libwebrtc.a <*.o>` I removed all the files which has

    U webrtc::AudioEncoder::OnReceivedUplinkBandwidth(int, absl::optional<long>)

I am still getting the linker errors.

Same thing is with other undefined reference errors other than `webrtc::VideoEncoder::SetFecControllerOverride` which I am not sure which target will provide.

> Could someone tell me other way to debug errors 1,2 and 3 as the
> symbols are there in libwebrtc.a.

> Why is it that in 1st and 3rd undefined reference errors they refer to errors in .cpp files than in a .o file like in error 2

Also how to find ninja target for
> error 4 undefined reference?

ykrisha...@gmail.com

unread,
Jul 17, 2020, 2:24:26 AM7/17/20
to discuss-webrtc
Hi all,
I was able to fix the above isssues as they were related to cxx_std_c++14 flag and once I set it the linker errors started passing.

But now I am getting a new issue: `task_queue_libevent.o` is not in the built `libwebrtc.a`

I have checked the flags `gn args out/Default --list=rtc_enable_libevent`, `gn args out/Default --list=rtc_build_libevent` and both are set to true.

I also searched for `*.a` file having `task_queue_libevent.o` but there was no such static file.

I also tried:
ninja -C . webrtc \
obj/rtc_base/rtc_task_queue_libevent/task_queue_libevent.o

But ninja says that nothing to do as it has already built the .o

Is there any way to build the libwebrtc.a with task_queue_libevent.o also added to it or we have to manually do that?

Thanks

ykrisha...@gmail.com

unread,
Jul 17, 2020, 3:39:57 AM7/17/20
to discuss-webrtc
I was going through the built artifacts and noticed that task_queue_libevent.o is part of peerconnect_client executable.
I could have used peerconnection_client but there is no corresponding static or shared lib related to peerconnection_client

I also had a look at webrtc.ninja which is getting generated and found that task_queue.o and task_queue_base.o are part of webrtc.ninja build statement for libwebrtc.a
But task_queue_libevent.o is not.

Now In my understanding gn uses webrtc.gni to generate corresponding webrtc.ninja file. It means that some argument needs to be passed to gn gen command
Currently my gn command looks like this:

gn gen out/Default --args='is_debug=false rtc_use_h264=true target_cpu="x64" target_os="linux" clang_use_chrome_plugins=false use_ghash=false symbol_level=2 use_custom_libcxx=false is_component_ffmpeg=true ffmpeg_branding="Chrome" rtc_include_tests=false rtc_build_examples=true rtc_build_tools=false use_rtti=true rtc_enable_protobuf=false rtc_use_h264=true rtc_link_pipewire=true proprietary_codecs=true'

Am I missing some argument which will lead to task_queue_libevent.o being added to build libwebrtc.a in webrtc.ninja?
On checking peerconnection_client.ninja it has obj/rtc_base/rtc_task_queue_libevent/task_queue_libevent.o and I am not understanding why.


As mentioned in previous comment I have checked

gn args out/Default --list=rtc_enable_libevent
gn args out/Default --list=rtc_build_libevent


And both are true
I am not sure what else is required.
Is there something which I am missing here?

Thanks.

ykrisha...@gmail.com

unread,
Jul 17, 2020, 9:22:22 AM7/17/20
to discuss-webrtc
Hi all
Was able to fix all the linker issue related to build by manually creating libwebrtc.a with all the required *.o files

Thanks

Eugene Foley

unread,
Jan 13, 2025, 4:42:17 AMJan 13
to discuss-webrtc
Do you by chance have any instructions or reference to instructions on how to do that?
Reply all
Reply to author
Forward
0 new messages