使用 OpenCV 构建 WebRTC

Build WebRTC with OpenCV

我正在尝试使用 OpenCV 构建 WebRTC。我用 cmake 构建了 OpenCV 并安装了它。在 PeerConnection 示例中,我包含了 opencv 库和 headers。当我调用 ninja build 时,出现以下错误:

ninja -C out/Default
ninja: Entering directory `out/Default'
[1/16] LINK ./peerconnection_client
FAILED: peerconnection_client 
../../third_party/llvm-build/Release+Asserts/bin/clang++ -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -ldl -lm -lpthread -lrt -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--no-as-needed -lpthread -Wl,--as-needed -fuse-ld=gold -B../../third_party/binutils/Linux_x64/Release/bin -Wl,--threads -Wl,--thread-count=4 -Wl,--icf=all -m64 -pthread -Werror --sysroot=../../build/linux/debian_wheezy_amd64-sysroot -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu/4.6 -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib -Wl,-rpath-link=. -Wl,--disable-new-dtags -Wl,-rpath=$ORIGIN/. -Wl,-rpath-link=. -Wl,--export-dynamic -o "./peerconnection_client" -Wl,--start-group @"./peerconnection_client.rsp" ./libboringssl.so ./libprotobuf_lite.so -Wl,--end-group  -lX11 -lXcomposite -lXext -lXrender -ldl -lrt -lgmodule-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lfreetype -lfontconfig -lgthread-2.0 -lglib-2.0 -lexpat -lm 
/usr/local/lib/libopencv_objdetect.so: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)', version 'GLIBCXX_3.4.20'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_shape.so: error: undefined reference to 'memcpy', version 'GLIBC_2.14'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)', version 'GLIBCXX_3.4.21'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

我的gcc版本是5.4.0。 定位 libstdc++.so.6 结果:

/home/parallels/webrt_blog/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrt_blog/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
/home/parallels/webrt_blog/src/third_party/llvm-build/Release+Asserts/lib/libstdc++.so.6
/home/parallels/webrtc/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrtc/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
/home/parallels/webrtc/src/third_party/llvm-build/Release+Asserts/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17-gdb.py
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17-gdb.py
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6.0.20
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6.0.20-gdb.py
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19-gdb.py
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19-gdb.py
/usr/lib/parallels-tools/installer/iagent32/libs/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent32/libs/libstdc++.so.6/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent64/libs/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent64/libs/libstdc++.so.6/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21-gdb.py

我猜 cmake opencv 使用 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21 而 webrtc ninja 似乎使用 libstdc++.so.6.0.16。这可能会造成一个conflict.Is这个冲突错误的原因?如果是,我该如何解决?

此问题是关于WebRTC和系统中库的libc和libstdc++库版本不兼容。

解决方法是复制两个文件,重建软links

  • 首先,复制/usr/lib/x86_64-linux-gnu/libstdc++.so.6.xx到这个路径/WebRTC/Path/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu并重建libstdc++.so.6link指向新复制的图书馆
  • 其次,复制/lib/x86_64-linux-gnu/libc-xx.so到/WebRTC/Path//home/faraklit/projects/webrtc-checkout/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu 并重建 libc.so.6 link 以指向新复制的库