2017-09-05 127 views
2

我試圖從WebRTC示例與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

這是不是與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::FatalMessagechecks.cc中定義,並由此BUILD.gn文件構建。

此前,rtc::FatalMessage::FatalMessage已包含在webrtc_base static library中,但看起來它已在最新版本中重命名。看起來,包含rtc::FatalMessage::FatalMessage的靜態庫目標現在是rtc_base

.a文件存在的問題之一是它們沒有描述它們所依賴的信息(如.so),所以在鏈接時由您決定是否獲得所有必需的文件,這些文件可以是當有很多.a文件時真的很痛苦。如果您可以自由移出CMake for your main項目,則可以與WebRTC框架的GN構建系統集成,這將幫助您處理鏈接到正確的依賴關係。