dynamic_cast fails when used with dlopen/dlsym

前端 未结 4 1052
灰色年华
灰色年华 2020-12-09 19:04

Intro

Let me apologise upfront for the long question. It is as short as I could make it, which is, unfortunately, not very short.

Setup

I have de

4条回答
  •  眼角桃花
    2020-12-09 19:41

    I found the answer to my question here. As I understand it, I need to make the typeinfo available in 'testc' available to the library 'testd'. To do this when using dlopen(), two extra things need to be done:

    • When linking the library, pass the linker the -E option, to make sure it exports all symbols to the executable, not just the ones that are unresolved in it (because there are none)
    • When loading the library with dlopen(), add the RTLD_GLOBAL option, to make sure symbols exported by testc are also available to testd

提交回复
热议问题