Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

linking libwebrtc.a into a c++ project

291 views
Skip to first unread message

Eugene Foley

unread,
Jan 2, 2025, 10:49:44 AMJan 2
to discuss-webrtc
1. Generated webrtc build files for Ubuntu 24 like so:

 gn gen out/Linux-x64 --args="target_os=\"linux\" target_cpu=\"x64\" is_debug=false rtc_include_tests=false rtc_use_h264=false is_component_build=false use_rtti=true use_custom_libcxx=false rtc_enable_protobuf=false"

According to instructions found here: https://github.com/webrtc-sdk/webrtc-build/blob/main/docs/build.md

2. gcc targets x86_64 arch:

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu

Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)

3. Attempting to link any one of the generated *.o files results in linker error (example below peer_connection.o):

g++ -o test test.cpp peer_connection.o
/usr/bin/ld: unknown architecture of input file `peer_connection.o' is incompatible with i386:x86-64 output
/usr/bin/ld: error in peer_connection.o(.eh_frame); no .eh_frame_hdr table will be created
collect2: error: ld returned 1 exit status

4. Checking file format of any of the *.o files that are components of libwebrtc.a show that they are generated for 64bit arch:

 readelf -h peer_connection.o
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          297960 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         1325
  Section header string table index: 1

Hints?

Aaron Clauson

unread,
Jan 2, 2025, 2:55:58 PMJan 2
to discuss-webrtc
If you're using a recent checkout of libwebrtc then the build will use the clang toolchain by default. That could explain why you're getting linker errors with the gcc toolchain.

Eugene Foley

unread,
Jan 10, 2025, 5:17:17 AMJan 10
to discuss-webrtc
Yes. I neglected to mentioned that I also attempted compile link with clang. Same error. 

clang --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang++ -o test test.cpp peer_connection.o
/usr/bin/ld: unknown architecture of input file `peer_connection.o' is incompatible with i386:x86-64 output
/usr/bin/ld: error in peer_connection.o(.eh_frame); no .eh_frame_hdr table will be created
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

With that said, I have another clarifying question: Where can i find a known good libwebrtc source code?

Currently I have been pulling the libwebrtc code by following instructions found here: https://dyte.io/blog/understanding-libwebrtc/

So I pull the code like so:

1. mkdir webrtc-checkout 2. cd webrtc-checkout 3. fetch --nohooks webrtc 4. gclient sync
5. Run the gn gen commands as seen in the top of the post.

When i check the source of the code I see:

git remote -v
origin  https://webrtc.googlesource.com/src.git (fetch)
origin  https://webrtc.googlesource.com/src.git (push)

So is  https://webrtc.googlesource.com/src.git known good source code?

Eugene Foley

unread,
Jan 13, 2025, 4:42:34 AMJan 13
to discuss-webrtc
Got linking working against libwebrtc.a

Following these instructions: https://medium.com/@tohntobshi/how-to-use-libwebrtc-c-native-library-and-how-i-am-making-webcam-platform-with-it-44bef9994850

I found that the thing that made a difference was to put myself on checkout: branch-heads/6030

Eugene Foley

unread,
Jan 15, 2025, 2:14:44 PMJan 15
to discuss-webrtc
Has anyone been able to get linking against c++ code to work on main branch?  branch-heads/6030  is from 9/2023  

Aaron Clauson

unread,
Jan 15, 2025, 2:39:39 PMJan 15
to discuss-webrtc
I recenly built and linked against tag m132 (25 Nov 2024) on both Ubuntu 20.04 and Windows 11.

The docker build files I used for the Ubuntu 20.04 build can be found here:

1. libwebrtc builder

2. app builder using libwebrtc.a from step 1

Eugene Foley

unread,
Jan 17, 2025, 3:58:36 PMJan 17
to discuss-webrtc
Aaron, 

Thank you for this! That really helps! I used that checkout and things build and link. Pulled myself up all the way to dec 17, 2024 looks like!

git log
commit afaf497805cbb502da89991c2dcd783201efdd08 (HEAD -> m132, branch-heads/6834)
Date:   Tue Dec 17 11:39:55 2024 +0800

That some builds work to link against and that some don't, does that mean there are builds that are understood to be stable and unstable, and if so, how can I identify stable releases? Are those marked somehow?

Not real easy to tell from here:   https://webrtc.googlesource.com/src.git 

-Best
Reply all
Reply to author
Forward
0 new messages