Symbol(s) duplication


  • Qt Champions 2016

    Hi,
    I'm getting a "multiple definition" error from the linker for no obvious reason. I have a simple utility class and I've ruled out the usual suspects. Here's the (stripped down) code:

    qdaemonstate_p.h

    QT_DAEMON_BEGIN_NAMESPACE
    
    class QDaemonState
    {
    public:
        QDaemonState(const QString &);
    
        void setPath(const QString &);
        void setArguments(const QStringList &);
        // ...
        QString path() const;
        QStringList arguments() const;
    
    private:
        struct Data
        {
            Data(const QString &);
    
            // ...
        } d;
    };
    
    // ------------------------------------------------------------------------------------ //
    
    inline void QDaemonState::setArguments(const QStringList & arguments)
    {
        d.arguments = arguments;
    }
    
    inline QString QDaemonState::path() const
    {
        return d.path;
    }
    
    inline QStringList QDaemonState::arguments() const
    {
        return d.arguments;
    }
    
    // ...
    
    QT_DAEMON_END_NAMESPACE
    
    Q_DECLARE_METATYPE(QtDaemon::QDaemonFlags)
    

    qdaemonstate.cpp

    #include "qdaemonstate_p.h"
    
    // ...
    
    QT_DAEMON_BEGIN_NAMESPACE
    
    QDaemonState::Data::Data(const QString & daemonName)
        : name(daemonName), initdPrefix(defaultInitDPath), dbusPrefix(defaultDBusPath), dbusTimeout(defaultDBusTimeout)
    {
    }
    
    QDaemonState::QDaemonState(const QString & name)
        : d(name)
    {
    }
    
    void QDaemonState::setPath(const QString & path)
    {
        // ...
    }
    
    QT_DAEMON_END_NAMESPACE
    

    The exact errors I get are:

    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::Data::Data(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::Data::Data(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::QDaemonState(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::QDaemonState(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::setPath(QString const&)'
    Makefile:120: recipe for target '../../lib/libQt5Daemon.so.0.1.0' failed
    // ...
    

    Obviously for some reason I get multiple instances for the out-of-line methods, but why I don't know yet.
    Any suggestions?


  • Qt Champions 2016

    It turned out very trivial. There was a source file path passed twice to qmake, which wasn't immediately obvious because of the subdirs template (the duplicate was in an included .pri file). This caused qmake to generate two targets for said file, and the linker is complaining because it tries to link twice the same translation unit.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.