undefined reference `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)' link v62

891 views
Skip to first unread message

Ankur Deep Jaiswal

unread,
Nov 17, 2017, 1:11:33 AM11/17/17
to discuss-webrtc

Hi,
 i am trying to build webrtc version 62 , using the following
1.git checkout -b branch62 refs/remotes/branch-heads/62
2.gn gen out_release_62/x64/Debug --args="rtc_include_tests=false rtc_use_h264=false use_rtti=true is_component_build=false enable_iterator_debugging=false enable_nacl=false target_os=\"linux\" target_cpu=\"x64\" is_debug=true"
3.ninja -C out_release_62/x64/Debug

i am linking to libwebrtc.a and libwebrtc_common.a

but wherever i try to use RTC_CHECK_EQ or RTC_DCHECK_LT i get the the following error:-  undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
and 
out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':

i had no issue with build branch head 59 , 
i tried linking to librtc_base.a and librtc_base_approved.a but no luck, 
any pointers for me

Ankur Deep Jaiswal

unread,
Nov 17, 2017, 4:39:48 AM11/17/17
to discuss-webrtc
A sample program that produces this error is 

#include <iostream>
#include <string>
#include <webrtc/rtc_base/checks.h>
#include <webrtc/rtc_base/ssladapter.h>
#include <webrtc/rtc_base/logging.h>
#include <webrtc/api/peerconnectioninterface.h>
using namespace std;

int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
std::string type;
std::string sdp;
webrtc::SdpParseError error;
webrtc::CreateSessionDescription(type,sdp,&error);
RTC_DCHECK(5);
RTC_CHECK_EQ(1,6);
RTC_DCHECK_LT(1,4);
return 0;
}

gcc verison 6.3 linker

g++ -L/home/test/webrtc-checkout-ankur/src/out_release_62/x64/Debug -o "testwebrtc"  ./src/testwebrtc.o   -lwebrtc -lwebrtc_common -lpthread -lm -ldl

this is the error that is returned

./src/testwebrtc.o: In function `main':
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:22: undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:24: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:25: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
./src/testwebrtc.o: In function `rtc::CheckEqImpl(int, int, char const*)':
makefile:45: recipe for target 'testwebrtc' failed
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:179: undefined reference to `std::string* rtc::MakeCheckOpString<int, int>(int const&, int const&, char const*)'
collect2: error: ld returned 1 exit status

Ankur Deep Jaiswal

unread,
Nov 17, 2017, 4:58:38 AM11/17/17
to discuss-webrtc
From my observation any function/method that has std::string in it is showing this behaviour

Ankur Deep Jaiswal

unread,
Nov 20, 2017, 4:37:32 AM11/20/17
to discuss-webrtc
I have successfully solved the issue, for all those poor souls who come across this, 
the explanation is very simple.

WebRTC builds itself using clang, it also by default uses libc++ bundled with clang, which postfixes every std namespace with __1, so std::string in g++ is std::string and in clang is std::__1::string,
so this will result in the application not linking properly to libwebrtc.a,

there are two solutions to this, 
1. use -stdlib=libc++ in your app, or
2. build webrtc using libstdc++that can be done by passing use_custom_libcxx=false and use_custom_libcxx_for_host=false to the gn gen args.

this was tested on an ubuntu 16.04 OS with GCC 5.4 

Alexandre GOUAILLARD

unread,
Nov 20, 2017, 10:57:49 AM11/20/17
to discuss...@googlegroups.com
thank you for finding the solution, and giving credits.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/b457e804-e46b-49c3-8400-6af32343d9bb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
President - CoSMo Software Consulting, Singapore
------------------------------------------------------------------------------------

Ankur Deep Jaiswal

unread,
Nov 20, 2017, 2:18:21 PM11/20/17
to discuss-webrtc
Hey Alex nothing like that, just an honest mistake. Please forgive me if you think I was taking it away from you. If I did mean something like that I would not given you bounty. I just did not know how to link two platforms. I did not even know you were here.

I had no reason to duplicate this information here, but that it would help someone else from the same fate.

Please forgive me if I hurt you.
> To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages