我尝试使用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
这是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(webrtcbridge)
add_compile_options(-std=c++11)
#Include PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
set(LIBYUV_LIBRARY_DIRS "/home/carlos/webrtc/webrtc-checkout/src/out/Release/obj/third_party/libyuv")
set(LIBYUV_INCLUDE_DIRS "/home/carlos/webrtc/webrtc-checkout/src/third_party/libyuv/include")
set(LIBWEBRTC_INCLUDE_DIRS "/home/carlos/webrtc/webrtc-checkout/src")
set(LIBWEBRTC_LIBRARY_DIRS "/home/carlos/webrtc/webrtc-checkout/src/out/Release/obj")
include_directories(${LIBWEBRTC_INCLUDE_DIRS})
link_directories(${LIBWEBRTC_LIBRARY_DIRS})
include_directories(${JSONCPP_INCLUDE_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
include_directories(${LIBYUV_INCLUDE_DIRS})
link_directories(${LIBYUV_LIBRARY_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBRTC_POSIX -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++0x -pthread")
#[[ Included Libraries
- LibWebRTC
- LibWebRTC_Common
- LibX11
- LibICE
- LibSM
- LibXext
- Libdl
- Librt
- LibJsoncpp
]]
set(LIBWEBRTC_LIBRARIES /home/carlos/webrtc/webrtc-checkout/src/out/Release/obj/webrtc/libwebrtc.a;/home/carlos/webrtc/webrtc-checkout/src/out/Release/obj/webrtc/libwebrtc_common.a;/usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libICE.so;/usr/lib/x86_64-linux-gnu/libSM.so;/usr/lib/x86_64-linux-gnu/libXext.so;dl;rt;/home/carlos/webrtc/webrtc-checkout/src/build/linux/debian_jessie_amd64-sysroot/usr/lib/libjsoncpp.a)
file(GLOB SOURCES src/*.cc)
add_executable(${PROJECT_NAME}_node
${SOURCES}
)
# WebRTC Libraries
target_link_libraries(${PROJECT_NAME}_node
${LIBWEBRTC_LIBRARIES}
)
# GTK libraries
target_link_libraries(${PROJECT_NAME}_node
${GTK3_LIBRARIES}
)
# JSONCPP libraries
target_link_libraries(${PROJECT_NAME}_node
${JSONCPP_LIBRARIES}
)
这似乎是Json库的问题,但是,因为您可以检入代码,它已经包含在内。
另一方面,它可能是内部json库的问题,但它应该包含在libwebrtc.a中,那么,可能是什么问题呢?
由于
答案 0 :(得分:0)
这不是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*)'
表示您错过了定义.a
的{{1}}。
rtc::FatalMessage::FatalMessage
在checks.cc中定义,由BUILD.gn个文件构建。
以前,rtc::FatalMessage::FatalMessage
中包含rtc::FatalMessage::FatalMessage
,但它似乎已在最新版本中重命名。包含rtc::FatalMessage::FatalMessage
的静态库目标现在似乎是 rtc_base 。
.a
文件存在的一个问题是,他们没有信息(例如.so
)来描述他们所依赖的内容,所以在链接时由您决定确保你获得了所有必需的文件,当有很多.a
文件时,这可能是一个真正的痛苦。如果您可以自由地从主要项目的CMake中移除,则可以与WebRTC框架的GN构建系统集成,这将帮助您处理与正确依赖关系的链接。
答案 1 :(得分:0)
不幸的是,库webrtc.a
并不是一个独立的库,至少对于branch-heads / 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_client示例的编译器标志列表,请检出out目录中生成的peerconnection_client.ninja文件的开头。
如果您有兴趣,我编写了一个生成器脚本,用于提取入门所需的文件。它甚至生成一个cmake文件以包含在您的项目中。我用它来快速设置自己的本地webrtc cmake项目。 (在撰写本文时,该脚本仅支持linux-amd64,但可以轻松扩展为其他平台和体系结构。) https://github.com/TekuConcept/WebRTCExamples/