Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTTI not set on linux/macos build? #53

Open
vans163 opened this issue Sep 30, 2017 · 6 comments
Open

RTTI not set on linux/macos build? #53

vans163 opened this issue Sep 30, 2017 · 6 comments

Comments

@vans163
Copy link

vans163 commented Sep 30, 2017

if you try to subclass a VideoCapturer or Thread you get

undefined reference to `typeinfo for cricket::VideoCapturer'
undefined reference to `typeinfo for rtc::Thread'

This seems to be because RTTI was not enabled in the build. It should be enabled by default for linux and macos.

-fno-rtti must be set on your app to avoid the problem. But there should at least be an option to include RTTI.

@agouaillard-cosmo
Copy link

  • even if you pass -fno-rtti on the app, you still have a problem. the solution would be to remove the "-fno-rtti" for all the classes you need to subclass.
  • RTTI is never enabled by default in libwebrtc. This is a google rule.
  • if you want to enable RTTI, you can use the "GN_EXTRA_ARGS" variable, and the GN "use_rtti" flag to enable RTTI for all the library. Be carefull, that almost double the size of the lib:

cmake -DGN_EXTRA_ARGS="use_rtti=true" <your_cmake_source_dir>

@vans163
Copy link
Author

vans163 commented Sep 30, 2017

/tmp/ccrPmQZO.o:(.data.rel.ro._ZTI15MyVideoCapturer[_ZTI15MyVideoCapturer]+0x18): undefined reference to `typeinfo for cricket::VideoCapturer'
/tmp/ccrPmQZO.o:(.data.rel.ro._ZTI15MyVideoCapturer[_ZTI15MyVideoCapturer]+0x28): undefined reference to `typeinfo for rtc::Thread'

Rebuilding the library (cd out && cmake -DGN_EXTRA_ARGS="use_rtti=true" ..) with make && make install and same error. I am statically linking libwebrtc.a instead of including the CMAKE build system into my app.

I have another issue but im not sure where it belongs, if its due to compile params or a bug in webrtc-src itself.

the media/base/fakevideocapturer.h has custom FOURCC_I420. When I try to run this code I crash here on SetCaptureFormat(&format):

  cricket::CaptureState Start(const cricket::VideoFormat& format) override {
    SetCaptureFormat(&format);    // <<< CRASH!
    running_ = true;
    SetCaptureState(cricket::CS_RUNNING);
    return cricket::CS_RUNNING;
  }

//With
*** Error in `./app': free(): invalid pointer: 0x00007f28c000a638 ***

If the capture format is default and not FOURCC_I420, there is no crash and SetCaptureFormat(&format) is called just fine.

Google seems to say this is a crash due to an out of bounds reference. But there is only 1 issue on github where the issues seems to indicate it depends on how the library was compiled.

Any idea if I should submit this here or on webrtc-src?

@agouaillard-cosmo
Copy link

  1. I am not sure axel's scripts allow for multiple runs. You need to double check:
  • go to the build directory (webrtc/src/out/<Release|Debug|Default> and check in the args.gn file that the use_rtti flag is set.
  • if yes, relaunch ninja without any argument from within that directory to see if it triggers new build. If it's a no-op, then you were ok. You still need to go back to the root and run "cmake --build ."
  1. if you do not use cmake to find webrtc, it is likely that your compilation flags, definitions, and include directories are wrong.

  2. if you link directly to libwebrtc, you have one chance out of two to link to the wrong one. Axel's scripts compile libwebrtc the google way (resulting in a lib you do NOT want to use), and then aggregate all the .o files in the build dir into another, bigger libwebrtc. The right way not to be confused if to install the library after the build ("cmake install"), and use the find_package() fonction of cmake in your application project to find the correct one.

  3. most of the video capture code is not exercised in the stand alone libwebrtc. Device Capture works mostly out of the box, once you understand the device info design, but the screen and apps capture is more complicated. This is an issue with libwebrtc itself, and you 'd rather ask about this on the webrtc-discuss mailing list.

just for verification purposes: you can use the mac installer on the following link to get an RTTI-enabled libwebrtc: https://drive.google.com/drive/folders/0B398g_p42xgrbUF3VjlFNnNxb3M?usp=sharing

@vans163
Copy link
Author

vans163 commented Sep 30, 2017

cat Release/args.gn
use_gold = false
target_cpu = "x64"
target_os = "linux"
is_component_build = false
is_debug = false
rtc_include_tests = false

Clearly use_rtti is not set :(.
Also i did a rm -rf libwebrtc and cloned + rebuild from 0.

The steps I did:

$ git clone https://github.com/aisouard/libwebrtc.git
$ cd libwebrtc
$ mkdir out
$ cd out
$ cmake -DGN_EXTRA_ARGS="use_rtti=true" ..

$ make
$ sudo make install
  1. Im compiling like so
g++ -DWEBRTC_POSIX -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++0x main.cpp -fno-rtti -g -o app 
-I ./lib/websocketpp/ -I ./lib/rapidjson/include/ -I ./lib/libwebrtc/out/include/ -lpthread -lSM -lICE -lX11 -lXext -ldl -lrt /usr/lib/x86_64-linux-gnu/libboost_system.a ./lib/libwebrtc/out/lib/libwebrtc.a

Everything works, i have datachannel working, video/audio channel negotiation, the only crash is on SetCaptureFormat(&format); when request format is I420 or H264, ex:I420 640x480x30.

  1. I am not using CMAKE in the application project, I just want to compile the libwebrtc and statically link it. Am I going down the wrong path, and I should just use CMAKE in my own project using libwebrtc? Which libwebrtc.a would be correct one?

  2. I think this maybe a difference in the stdlib libwebrtc.a was compiled with and my app, is there anyway to confirm? Sorry for being a little offtopic here but this is the backtrace. To me it looks like some kind of convention error or smart pointer error.

#0  0x00007ffff620a428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff620c02a in __GI_abort () at abort.c:89
#2  0x00007ffff624c7ea in __libc_message (do_abort=do_abort@entry=2, 
    fmt=fmt@entry=0x7ffff6365e98 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff625537a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, 
    str=0x7ffff6362c6f "free(): invalid pointer", action=3) at malloc.c:5006
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3867
#5  0x00007ffff625953c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968
#6  0x00005555555eccb4 in std::default_delete<cricket::VideoFormat>::operator() (this=0x7fffe800a3f8, __ptr=0x7fffe800a868)
    at /usr/include/c++/6/bits/unique_ptr.h:76
#7  0x00005555555e46ed in std::unique_ptr<cricket::VideoFormat, std::default_delete<cricket::VideoFormat> >::reset (
    this=0x7fffe800a3f8, __p=0x7fffe800a868) at /usr/include/c++/6/bits/unique_ptr.h:347
#8  0x00005555555cd24a in cricket::VideoCapturer::SetCaptureFormat (this=0x7fffe800a320, format=0x7fffef5149f0)
    at ./lib/libwebrtc/out/include/webrtc/media/base/videocapturer.h:235

I am on linux, no macos here :(, but the issue was reported by macos users on indie projects using this libwebrtc.

@agouaillard
Copy link

agouaillard commented Oct 2, 2017 via email

@jiefugong
Copy link

Hate to bring this back up, but I'm running into this issue now and even after adding the RTTI flag I still don't see any change in the args.gn file. Is there anything else I can do or verify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants