libmediasoupclient build-env:
POSIX, cmake >= 3.5, gcc and g++ >= 4.9 or clang (win with C++11 support)
refer: https://mediasoup.org/documentation/v3/libmediasoupclient/installation/
由于libmediasoupclient使用libwebrtc,所以如果想编译libmediasoupclient,需先编译libwebrtc.
build libwebrtc:
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=$PATH:/home/opc/ms/depot_tools
$ mkdir webrtc_checkout;cd webrtc_checkout;fetch --nohooks webrtc;gclient sync
$ git checkout -b m94 refs/remotes/branch-heads/4606;gclient sync
$ gn gen out/m94 --args='target_cpu="x64" is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_x11=false use_glib=false'
// use_custom_libcxx=false 就是使用stdc++11 use_ozone=true use_custom_libcxx_for_host=false
$ gn gen out/m94 --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=false use_rtti=true treat_warnings_as_errors=false use_ozone=true use_x11=false use_glib=false use_custom_libcxx=true use_custom_libcxx_for_host=true'
// 缺省使用libc++11而不是stdc++11
$ ninja -C out/m94
build libmediasoupclient
$ git clone https://github.com/versatica/libmediasoupclient.git
$ cmake . -Bbuild -DLIBWEBRTC_INCLUDE_PATH:PATH=/home/admin/workspace/ms/webrtc_checkout/src -DLIBWEBRTC_BINARY_PATH:PATH=/home/admin/workspace/ms/webrtc_checkout/src/out/m94/obj
$ make -C build/
编译中碰到的问题
1. webrtc版本。虽然branch-heads/4606有点旧,但mediasoup用的就是这个版本。
我没有尝试用最新的branch-heads/5113或master这些版本。
2. gcc版本问题
我是用linux下面编译,按要求是g++ >= 4.9
我先把g++版本升级到10.2
$ sudo yum -y install centos-release-scl
$ sudo yum -y install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils
$ sudo scl enable devtoolset-10 bash
$ sudo echo "source /opt/rh/devtoolset-10/enable" >>/etc/profile
碰到问题:
/home/opc/ms/depot_tools/webrtc_checkout/src/buildtools/linux64/gn: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /home/opc/ms/depot_tools/webrtc_checkout/src/buildtools/linux64/gn)
下载glibc_2.18 wget http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.18.tar.gz
configure出错:configure: error:
*** These critical programs are missing or too old: gcc
*** Check the INSTALL file for required versions.
这个问题处理起来有点麻烦,我选择编译webrtc时避免使用glibc这个库存。use_glib=false
3. c++11链接问题 undefined reference to `std::__cxx11::basic_string
编译libmediasoup比较顺利,但链接生成应用程序就出错了!
/usr/bin/ld: ./sdk/libmsv3.a(Handler.cpp.o): in function `mediasoupclient::Handler::GetNativeRtpCapabilities[abi:cxx11](mediasoupclient::PeerConnection::Options const*)':
Handler.cpp:(.text+0x13c): undefined reference to `sdptransform::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ./sdk/libmsv3.a(Handler.cpp.o): in function `mediasoupclient::Handler::SetupTransport(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>&)':
google的结果是c++11与旧的c++库函数实现存在差别,当本地的c++代码动态库为旧版本c++库所实现,而编译器g++5,gcc5将其解释为std::__cxx11,就会出现未定义错误,那么须要指定编译器的版本为g++4,gcc4,再进行编译时就不会发生上述问题。
需要升级gcc/g++。我采用编译来升级gcc到gcc-12
$ wget https://ftp.gnu.org/gnu/gcc/gcc-12.1.0/gcc-12.1.0.tar.gz;
$ tar xzf gcc-12.1.0.tar.gz
cd gcc-12.1.0
./contrib/download_prerequisites
cd ..
mkdir build;cd build
../configure --enable-languages=c,c++,go --prefix=/usr/local/gcc-12 -disable-multilib;make;sudo make install