WEBRTC的未定义参考
Undefined references with WebRTC
我正在尝试从WEBRTC示例中构建使用CMAKE的对等连接客户端以在我的项目中使用它。
我已经包含了所有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中,所以有什么问题?
谢谢
这不是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
在checks.cc中定义,并由此build.gn文件构建。
以前,rtc::FatalMessage::FatalMessage
已包含在WebRTC_Base静态库中,但看起来它已在最新版本中重命名。看来包含rtc::FatalMessage::FatalMessage
的静态库目标现在为 rtc_base 。
.a
文件的问题之一是它们没有信息(例如.so
)描述其依赖的信息,因此在链接时间取决于您,以确保您获得所有必需的文件,这可以是一个当有很多.a
文件时,真正的痛苦。如果您可以自由地从CMAKE为主要项目转移,则可以与WEBRTC Framework的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
添加到编译器标志中。RTTI默认是WEBRTC构建中的禁用。
要查看用于构建PeerConnection_client示例的编译器标志列表,请查看您OUT目录中生成的PeerConnection_Client.ninja文件的开头。
如果您有兴趣,我编写了一个小生成器脚本,该脚本提取了入门所需的文件。它甚至会生成一个CMAKE文件,其中包括您的项目中。我使用它来快速设置自己的本机WebRTC Cmake项目。(在撰写本文时,脚本仅支持Linux-AMD64,但可以轻松地扩展到其他平台和体系结构。)https://github.com/tekuconcept/webrtcexamples/
- GTest EXPECT_EQ给出未定义的错误参考
- 在VSCode中编译C++给了我一个未定义的参考
- Armadillo正在为共享的lapack库获取未定义的参考
- 我对C++程序有一个未定义的参考,不知道如何处理它
- 未定义的符号参考'pthread_rwlock_wrlock@@GLIBC_2.2.5'
- 新的C ,未定义的参考
- ROS中未定义的参考误差到OpenCV图像转换器
- 使用Arduino IDE的构造函数的未定义参考错误
- 未定义的参考错误链接天然函数Android
- QT的倍频程:未定义的参考
- 未定义的参考,差异使用 CUDA 的 OpenCV 中的双边过滤器
- MSYS2静态QT未定义的参考问题
- LLVM-5.0 MakeFile未定义的参考失败
- 尝试在Windows结果上使用GLOG未定义的参考
- 从链接中缺少什么,导致未定义的参考
- 带有静态库的Android NDK:链接器始终抛出“未定义的参考”
- Lambdas的C 向量 - 未定义的参考
- __extern_inline func导致未定义的参考错误
- OPENCV筛选未定义的参考问题
- C 指针未定义的参考