Cannot evaluate function — may be inlined

后端 未结 2 1826
既然无缘
既然无缘 2021-01-01 13:44

I wrote a function similar to this:

class abc {
    private :
    int m_var ;
    public :
    int func() { return m_var ; }
};

When I try

相关标签:
2条回答
  • 2021-01-01 14:17

    You got this error because you put func's definition in the class body and it's small enough, so, first, the compiler inlined this function ---- that means, the compile will substitute all the appearance of this function's call with its definition, and no definition of this function will be in the executable file. And, second, you didn't really call that function in your program, so in fact, this function never exist in your final executable file!

    To solve that:

    1. You can put the definition of func outside the class body.
    2. Call func in your program anywhere.
    0 讨论(0)
  • 2021-01-01 14:27

    When the function is inlined, it doesn't appear as a proper symbol in the executable, so there's no way for gdb to execute it. The simplest thing to do is probably to compile with function inlining disabled, either by -fno-inline-functions or (still better) -O0.

    0 讨论(0)
提交回复
热议问题