Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

'Undefined interface' when including from /usr/include



  • Hello all!

    I have an interface defined like this (minimal example):
    @
    #ifndef IPLUGIN_H_
    #define IPLUGIN_H_

    class IPlugin
    {
    public:
    virtual ~IPlugin() { }
    virtual int getVersion() = 0; //Arbitrary, isn't needed to recreate error
    };

    QT_BEGIN_NAMESPACE
    Q_DECLARE_INTERFACE(IPlugin, "com.xarxer.IPlugin")
    QT_END_NAMESPACE

    #endif
    @

    The IPlugin header file is placed in /usr/include/c++/4.7.2/MyStuff/
    In my .pro file, I do this:
    @
    INCLUDEPATH += /usr/include/c++/4.7.2/MyStuff
    @

    I've also tried variants of INCLUDEPATH such as "-I /usr/include/[...]" etc.

    And in my plugin library (Shared library project) I do this:
    @
    #ifndef MYPLUGIN_H_
    #define MYPLUGIN_H_

    #include <QObject>
    #include <IPlugin> //Tried variants such as <MyStuff/IPlugin>, <MyStuff/IPlugin.h> (with and without .h in the extension on the file etc.)

    class MyPlugin : public QObject, public IPlugin
    {
    Q_OBJECT
    Q_INTERFACES(IPlugin) //This is what generates the error
    //Also tried with and without Q_PLUGIN_METADATA

    public:
    ~MyPlugin() { }
    virtual int getVersion() { return 1; }
    };

    #endif
    @

    But when I compile I get the error "Undefined interface".

    However, if I move the file from /usr/include/[...] to my actual project directory, then the compiler recognizes the interface.
    This really seems like a bug in the compiler or something. Any ideas?

    Thanks in advance!



  • INCLUDEPATH points to the location of the header files and LIBS points to the location of the share library. Make sure that you have set a correct path for LIBS. Read the following wiki article for details and examples of both linking shared library and loading it with QLibrary: "How to create a library with Qt and use it in an application":http://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application



  • Well, the issue is that the shared library project doesn't compile at all. However, I tried the exact same code on Windows today, and it works fine. I shall experiment a bit with permissions on the include folder as soon as I get home, altough I don't think that's the issue at hand..

    EDIT: Nope, exact same code under Linux does not compile, compiler gives the error 'Undefined interface'. Any help greatly appreciated! :-(



  • Hello again. I've been experimenting some.

    If I do this in my .pro file:
    @
    INCLUDEPATH += /usr/include/c++/4.7.2/MyStuff
    @

    and this in my header file:
    @
    #include <IPlugin.h>
    @

    It does not compile, and the compiler says "Undefined interface".
    If I omit the INCLUDEPATH, it doesn't compile either, and this really should be omittable since /usr/include is included per default.
    However, if I do this in my .pro file:
    @
    INCLUDEPATH += /usr
    @

    and this in my header file:
    @
    #include <include/c++/4.7.2/MyStuff/IPlugin.h>
    @

    It compiles nicely!
    The former configuration does not generate moc_ files if that matters.

    Again, any help at all in understanding what the problem is is greatly appreciated!


Log in to reply