Search code examples
c++g++rtti

-frtti has no effect to "undefined reference to typeinfo" but -fno-rtti does


In my code, I implements a class inherits a derived class (class QualityOfBrightness in <seeta/QualityOfBrightness.h> ) from a third library.(https://github.com/SeetaFace6Open/index)

If my code is compiled with -frtti or no options, it will throw error undefined reference to "typeinfo seeta::v3::QualityOfBrightness" when linking.

If compiled with -fno-rtti, it will link successfully.

So I recompiled the third library with -frtti so that I can use it with code compiled with -frtti.

But it has no effect.I still need to add -fno-rtti so that my code can compile. I used to see the CMakeOutput.log and it does be compiled with -frtti.

If -fno-rtti added, I need to recompile opencv with it and I won't be able to use typeid, dynamic_castetc.

I don't know what to do next. I'm sure all functions have been defined. Is there any other posibility causing this?

My compiler is gcc10.2, my OS is debian 11 (bullseye).

Below is an example:

#include <seeta/QualityOfBrightness.h>

using namespace seeta;

class Handler: public QualityOfBrightness {
public:

    Handler() : QualityOfBrightness() {};
    ~Handler()  {};
    QualityResult
    check (
        const SeetaImageData &image,
        const SeetaRect &face,
        const SeetaPointF *points,
        const int32_t N) override {
        return QualityResult (QualityLevel::HIGH);
    };
};

int
main (void)
{
    Handler a;
}

The class QualityOfBrightness and its base class QualityRule are from a third library .(If you need to see more, see https://github.com/SeetaFace6Open/index)


class QualityOfBrightness : public QualityRule {
public:
    using self = QualityOfBrightness;
    using supper = QualityRule;
    
    SEETA_API QualityOfBrightness();

    SEETA_API QualityOfBrightness (float v0, float v1, float v2, float v3);
    
    SEETA_API ~QualityOfBrightness() override;
    
    SEETA_API QualityResult check (
        const SeetaImageData &image,
        const SeetaRect &face,
        const SeetaPointF *points,
        const int32_t N) override;
        
private:
    QualityOfBrightness (const QualityOfBrightness &) = delete;
    QualityOfBrightness &operator= (const QualityOfBrightness &) = delete;
    
private:
    void *m_data;
};
class QualityRule {
public:
    using self = QualityRule;
    
    virtual ~QualityRule() = default;
    
    virtual QualityResult check (
        const SeetaImageData &image,
        const SeetaRect &face,
        const SeetaPointF *points,
        int32_t N) = 0;
};

Solution

  • Oh.I find the third library is compiled with another option -fvisibility=hidden. If I remove it, then my code can compile withoud -fno-rtti. So ,I think, the bug results from this option.