C++ 使用WebRTC的未定义引用

C++ 使用WebRTC的未定义引用,c++,cmake,webrtc,C++,Cmake,Webrtc,我正在尝试使用cmake从WebRTC示例构建对等连接客户端,以便在我的项目中使用它 我已经包括了所有webrtc库等来构建它,但我总是遇到同样的问题: CMakeFiles/webrtcbridge_node.dir/src/webrtcbridge_node.cc.o:(.rodata._ZTI18CustomSocketServer[_ZTI18CustomSocketServer]+0x10): undefined reference to `typeinfo for rtc::Phys

我正在尝试使用cmake从WebRTC示例构建对等连接客户端,以便在我的项目中使用它

我已经包括了所有webrtc库等来构建它,但我总是遇到同样的问题:

CMakeFiles/webrtcbridge_node.dir/src/webrtcbridge_node.cc.o:(.rodata._ZTI18CustomSocketServer[_ZTI18CustomSocketServer]+0x10): undefined reference to `typeinfo for rtc::PhysicalSocketServer'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function `Conductor::OnMessageFromPeer(int, std::string const&)':
conductor.cc:(.text+0x294d): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)'
conductor.cc:(.text+0x2aed): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)'
conductor.cc:(.text+0x2c01): undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
conductor.cc:(.text+0x2f46): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)'
conductor.cc:(.text+0x2fa7): undefined reference to `rtc::GetIntFromJsonObject(Json::Value const&, std::string const&, int*)'
conductor.cc:(.text+0x3004): undefined reference to `rtc::GetStringFromJsonObject(Json::Value const&, std::string const&, std::string*)'
conductor.cc:(.text+0x3190): undefined reference to `webrtc::CreateIceCandidate(std::string const&, int, std::string const&, webrtc::SdpParseError*)'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function  `Conductor::OnSuccess(webrtc::SessionDescriptionInterface*)':
conductor.cc:(.text+0x53e9): undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function  `rtc::ArrayView<int, -4711l>::ArrayView<int>(int*, unsigned long)':
conductor.cc:(.text._ZN3rtc9ArrayViewIiLln4711EEC2IiEEPT_m[_ZN3rtc9ArrayViewIiLln4711EEC5IiEEPT_m]+0xd4): undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
conductor.cc:(.text._ZN3rtc9ArrayViewIiLln4711EEC2IiEEPT_m[_ZN3rtc9ArrayViewIiLln4711EEC5IiEEPT_m]+0x15a): undefined reference to  `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
conductor.cc:(.text._ZN3rtc9ArrayViewIiLln4711EEC2IiEEPT_m[_ZN3rtc9ArrayViewIiLln4711EEC5IiEEPT_m]+0x200): undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function  `rtc::ArrayView<rtc::IntervalRange, -4711l>::ArrayView<rtc::IntervalRange>(rtc::IntervalRange*, unsigned long)':
conductor.cc:(.text._ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC2IS1_EEPT_m[_ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC5IS1_EEPT_m]+0xd4): undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
conductor.cc:(.text._ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC2IS1_EEPT_m[_ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC5IS1_EEPT_m]+0x15a): undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o:conductor.cc:(.text._ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC2IS1_EEPT_m[_ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC5IS1_EEPT_m]+0x200): more undefined references `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
CMakeFiles/webrtcbridge_node.dir/src/conductor.cc.o: In function  `std::string* rtc::CheckEqImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)':
conductor.cc:(.text._ZN3rtc11CheckEqImplImmEEPSsRKT_RKT0_PKc[_ZN3rtc11CheckEqImplImmEEPSsRKT_RKT0_PKc]+0x4b): undefined reference to `std::string* rtc::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)'
CMakeFiles/webrtcbridge_node.dir/src/peer_connection_client.cc.o: In function `PeerConnectionClient::Connect(std::string const&, int, std::string const&)':
peer_connection_client.cc:(.text+0xc97): undefined reference to `rtc::SocketAddress::SetIP(std::string const&)'
CMakeFiles/webrtcbridge_node.dir/src/peer_connection_client.cc.o:(.rodata._ZTI20PeerConnectionClient[_ZTI20PeerConnectionClient]+0x28): undefined reference to `typeinfo for rtc::MessageHandler'
collect2: error: ld returned 1 exit status
webrtcbridge/CMakeFiles/webrtcbridge_node.dir/build.make:205: recipe for target 'webrtcbridge/webrtcbridge_node' failed
make[2]: *** [webrtcbridge/webrtcbridge_node] Error 1
CMakeFiles/Makefile2:878: recipe for target 'webrtcbridge/CMakeFiles/webrtcbridge_node.dir/all' failed
make[1]: *** [webrtcbridge/CMakeFiles/webrtcbridge_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed 
make: *** [all] Error 2
Invoking "make -j2 -l2" failed
Json库似乎有问题,但正如您可以签入代码一样,它已经包含在内了

另一方面,内部json库可能有问题,但它应该包含在libwebrtc.a中。那么,问题出在哪里呢


谢谢

这不是Json库的问题,而是缺少一些必需的
.a
文件。例如,以下链接错误:

conductor.cc:(.text._ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC2IS1_EEPT_m[_ZN3rtc9ArrayViewINS_13IntervalRangeELln4711EEC5IS1_EEPT_m]+0xd4): undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
表示您缺少定义
rtc::FatalMessage::FatalMessage
.a

rtc::FatalMessage::FatalMessage
在中定义并由该文件生成

以前,
rtc::FatalMessage::FatalMessage
包含在中,但在最新版本中似乎已重命名。似乎包含
rtc::FatalMessage::FatalMessage
的静态库目标现在是rtc_base


.a
文件的一个问题是,它们没有描述它们所依赖的内容的信息(如
.so
),因此,在链接时,您需要确保获得所有必需的文件,当有大量
.a
文件时,这可能是一个真正的难题。如果您可以自由地离开CMake for Your主项目,您可以与WebRTC框架的GN构建系统集成,这将帮助您处理到正确依赖项的链接。

WebRTC.a
不是一个完全独立的库,不幸的是,至少对于分支负责人/72来说不是。它需要许多附加的第三方依赖项,您必须使用特定的编译器/链接器标志进行构建,才能使所有这些都正常工作

根据我自己项目的结果,所需的库是

    rtc_base/json.o
    third_party/jsoncpp/json_reader.o
    third_party/jsoncpp/json_writer.o
    third_party/jsoncpp/json_value.o
    test/field_trial.o
    X11 Xcomposite Xext Xrender atomic dl pthread rt
    gmodule-2.0 gtk-3 gdk-3 pangocairo-1.0 pango-1.0
    atk-1.0 cairo-gobject cairo gdk_pixbuf-2.0 gio-2.0
    gobject-2.0 gthread-2.0 glib-2.0 m jsoncpp
关于第一个错误(typeinfo),您需要在启用RTTI的情况下构建webrtc,或者在编译器标志中添加
-fno RTTI
。默认情况下,在webrtc生成中禁用RTTI

要查看用于构建peerconnection_客户端示例的编译器标志列表,请查看out目录中生成的peerconnection_client.ninja文件的开头

如果您感兴趣,我编写了一个小生成器脚本,用于提取入门所需的文件。它甚至会生成一个cmake文件以包含在项目中。我使用它快速设置自己的原生webrtc cmake项目。(在编写本文时,该脚本仅支持linux-amd64,但可以轻松地扩展到其他平台和体系结构。)

    rtc_base/json.o
    third_party/jsoncpp/json_reader.o
    third_party/jsoncpp/json_writer.o
    third_party/jsoncpp/json_value.o
    test/field_trial.o
    X11 Xcomposite Xext Xrender atomic dl pthread rt
    gmodule-2.0 gtk-3 gdk-3 pangocairo-1.0 pango-1.0
    atk-1.0 cairo-gobject cairo gdk_pixbuf-2.0 gio-2.0
    gobject-2.0 gthread-2.0 glib-2.0 m jsoncpp