Declaring abstract class (pure virtual method) increase binary size substantially

前端 未结 2 1835
无人及你
无人及你 2021-01-02 11:46

Here is the story: I am developing C++ software for ARM Cortex-M0 processor in Linux with AC6 Toolpack. Before I was using Keil (in windows) (who has their own toolchain) a

2条回答
  •  时光说笑
    2021-01-02 12:15

    It's almost certainly because of unexpected inclusion of exception handling, which libc++ has built into it, regardless of whether or not you compile your code with --noexception or whatever the proper gnu-ism is.

    The exception in question is probably 'pure virtual function call' or something like that (a fairly obscure runtime error to get, but possible if you call virtual functions in the base class constructor).

    The answer is to provide your own empty implementation of this, atexit(), and whatever random callout that you don't really need. Once you do that, the linker won't drag in the other stuff (which drags in other stuff, which drags in other stuff, etc).

    void __cxa_pure_virtual(void) 
    { 
        BKPT();
    }
    

    Is what I have on our project, though things may have changed in your version of libc++

提交回复
热议问题