Author Topic: Duplicate symbol error  (Read 8940 times)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Duplicate symbol error
« on: October 01, 2023, 01:07:51 am »
So I tried to compile the latest smplayer, it went pretty well, a couple of minor fixes, until it got to screensaver.cpp where it tried to take the *nix path of disabling power savings.
Investigation showed that winscreensaver.cpp had the code to disable Doodles screensaver, so fixed screensaver.cpp/h by changing all the #ifdef Q_OS_WIN to #if defined (Q_OS_WIN) || defined (Q_OS_OS2), made sure that winscreensaver.cpp was compiled on OS/2 and screensaver.cpp compiled fine. Linking died with,
Code: [Select]
weakld: K:\work\smplayer\build\screensaver.obj - error: Duplicate symbol '__ZN11ScreenSaverD2Ev' ('__ZN11ScreenSaverD2Ev').
weakld: K:\work\smplayer\build\screensaver.obj - error: Symbol previosly defined in this module.
weakld: info: fFlags new 0x0001  fFlags old 0x0001 (PUBLIC).
emxomfld: weak prelinker failed. (rc=-1)
make.exe: *** [Makefile:794: smplayer.exe] Error 1

K:\work\smplayer\build>c++filt __ZN11ScreenSaverD2Ev
ScreenSaver::~ScreenSaver()

I don't understand where the duplicate symbol is coming from. The code,
Code: [Select]
#include "screensaver.h"

#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
#include "winscreensaver.h"
#endif
#ifdef OS_UNIX_NOT_MAC
#include "powersaving.h"
#endif
#ifdef Q_OS_MACX
#include "powersaving_mac.h"
#endif

ScreenSaver::ScreenSaver(QObject * parent) : QObject(parent) {
#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
win_screensaver = new WinScreenSaver();
#else
power_saving = new PowerSaving(this);
#endif
}

ScreenSaver::~ScreenSaver() {
#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
delete win_screensaver;
#endif
}

void ScreenSaver::enable() {
#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
win_screensaver->enable();
#else
power_saving->uninhibit();
#endif
}

void ScreenSaver::disable() {
#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
win_screensaver->disable();
#else
power_saving->inhibit();
#endif
}

#include "moc_screensaver.cpp"

screensaver.h
Code: [Select]
#ifndef SCREENSAVER_H
#define SCREENSAVER_H

#include <QObject>

class PowerSaving;
class WinScreenSaver;

class ScreenSaver : public QObject
{
        Q_OBJECT

public:
        ScreenSaver(QObject * parent = 0);
        ~ScreenSaver();

public slots:
        void enable();
        void disable();

protected:
#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
        WinScreenSaver * win_screensaver;
#else
        PowerSaving * power_saving;
#endif
};

#endif

Winscreensaver.cpp is at https://github.com/smplayer-dev/smplayer/blob/master/src/winscreensaver.cpp change the .cpp to h for the header.
Ideas?

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2281
  • Karma: +176/-0
    • View Profile
Re: Duplicate symbol error
« Reply #1 on: October 01, 2023, 02:13:44 am »
Are you sure the codepath below isn't being called?
Code: [Select]
#ifdef OS_UNIX_NOT_MAC
#include "powersaving.h"
#endif

https://github.com/smplayer-dev/smplayer/blob/master/src/screensaver.cpp#L24C1-L26C7

Afterall, we are often OS_UNIX and not MAC :)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #2 on: October 01, 2023, 02:27:43 am »
Pretty sure, there was a lot of errors about powermanager before I added the OS/2 defines.
I do see that winscreensaver.cpp isn't being compiled. I patched smplayer.pro like this,
Code: [Select]
--- a/src/smplayer.pro
+++ b/src/smplayer.pro
@@ -593,7 +593,7 @@ contains( DEFINES, SCREENSAVER_OFF ) {
                HEADERS += powersaving.h
                SOURCES += powersaving.cpp
        }
-       win32 {
+       win32:os2 {
                HEADERS += winscreensaver.h
                SOURCES += winscreensaver.cpp
        }
Is that the correct way to add OS/2 support?

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #3 on: October 01, 2023, 02:50:28 am »
Are you sure the codepath below isn't being called?
Code: [Select]
#ifdef OS_UNIX_NOT_MAC
#include "powersaving.h"
#endif

https://github.com/smplayer-dev/smplayer/blob/master/src/screensaver.cpp#L24C1-L26C7

Afterall, we are often OS_UNIX and not MAC :)

Anyways, commented out the OS_UNIX_NOT_MAC chunk, no difference. Also fixed the pro file so winscreensaver.cpp is compiled.
Ran emxexp on screensaver.obj and don't see the duplicate symbol,
Code: [Select]
K:\work\smplayer\build>emxexp screensaver.obj
  ; segment DATA32
  "__ZN11ScreenSaver16staticMetaObjectE"                                ; magics
eg='DATA32' len=36

  ; segment TEXT32
  "__ZN11ScreenSaverD2Ev"                                               ; magics
eg='TEXT32' len=21
  "__ZN11ScreenSaverD1Ev"                                               ; magics
eg='TEXT32' len=21
  "__ZN11ScreenSaverD0Ev"                                               ; magics
eg='TEXT32' len=21
  "__ZNK11ScreenSaver10metaObjectEv"                                    ; magics
eg='TEXT32' len=32
  "__ZN11ScreenSaver18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv"
            ; magicseg='TEXT32' len=71
  "__ZN11ScreenSaverC2EP7QObject"                                       ; magics
eg='TEXT32' len=29
  "__ZN11ScreenSaverC1EP7QObject"                                       ; magics
eg='TEXT32' len=29
  "__ZN11ScreenSaver6enableEv"                                          ; magics
eg='TEXT32' len=26
  "__ZN11ScreenSaver7disableEv"                                         ; magics
eg='TEXT32' len=27
  "__ZN11ScreenSaver11qt_metacastEPKc"                                  ; magics
eg='TEXT32' len=34
  "__ZN11ScreenSaver11qt_metacallEN11QMetaObject4CallEiPPv"             ; magics
eg='TEXT32' len=55
  "__ZTV11ScreenSaver"                                                  ; magics
eg='TEXT32' len=18  weak
  "__ZTS7QObject"                                                       ; magics
eg='TEXT32' len=13  weak
  "__ZTI7QObject"                                                       ; magics
eg='TEXT32' len=13  weak
  "__ZTS11ScreenSaver"                                                  ; magics
eg='TEXT32' len=18  weak
  "__ZTI11ScreenSaver"                                                  ; magics
eg='TEXT32' len=18  weak

Irritating.

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: Duplicate symbol error
« Reply #4 on: October 01, 2023, 03:50:57 am »
So what does "moc_screensaver.cpp" contain ?

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #5 on: October 01, 2023, 09:38:49 am »
So what does "moc_screensaver.cpp" contain ?

Good question. Seems to be a generated file that is not compiled and only in build/ which I created to do the compile in.
Code: [Select]
/****************************************************************************
** Meta object code from reading C++ file 'screensaver.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include <memory>
#include "../src/screensaver.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'screensaver.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.15.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_ScreenSaver_t {
    QByteArrayData data[4];
    char stringdata0[28];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
    Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
    qptrdiff(offsetof(qt_meta_stringdata_ScreenSaver_t, stringdata0) + ofs \
        - idx * sizeof(QByteArrayData)) \
    )
static const qt_meta_stringdata_ScreenSaver_t qt_meta_stringdata_ScreenSaver = {
    {
QT_MOC_LITERAL(0, 0, 11), // "ScreenSaver"
QT_MOC_LITERAL(1, 12, 6), // "enable"
QT_MOC_LITERAL(2, 19, 0), // ""
QT_MOC_LITERAL(3, 20, 7) // "disable"

    },
    "ScreenSaver\0enable\0\0disable"
};
#undef QT_MOC_LITERAL

static const uint qt_meta_data_ScreenSaver[] = {

 // content:
       8,       // revision
       0,       // classname
       0,    0, // classinfo
       2,   14, // methods
       0,    0, // properties
       0,    0, // enums/sets
       0,    0, // constructors
       0,       // flags
       0,       // signalCount

 // slots: name, argc, parameters, tag, flags
       1,    0,   24,    2, 0x0a /* Public */,
       3,    0,   25,    2, 0x0a /* Public */,

 // slots: parameters
    QMetaType::Void,
    QMetaType::Void,

       0        // eod
};

void ScreenSaver::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
    if (_c == QMetaObject::InvokeMetaMethod) {
        auto *_t = static_cast<ScreenSaver *>(_o);
        Q_UNUSED(_t)
        switch (_id) {
        case 0: _t->enable(); break;
        case 1: _t->disable(); break;
        default: ;
        }
    }
    Q_UNUSED(_a);
}

QT_INIT_METAOBJECT const QMetaObject ScreenSaver::staticMetaObject = { {
    QMetaObject::SuperData::link<QObject::staticMetaObject>(),
    qt_meta_stringdata_ScreenSaver.data,
    qt_meta_data_ScreenSaver,
    qt_static_metacall,
    nullptr,
    nullptr
} };


const QMetaObject *ScreenSaver::metaObject() const
{
    return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}

void *ScreenSaver::qt_metacast(const char *_clname)
{
    if (!_clname) return nullptr;
    if (!strcmp(_clname, qt_meta_stringdata_ScreenSaver.stringdata0))
        return static_cast<void*>(this);
    return QObject::qt_metacast(_clname);
}

int ScreenSaver::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
        if (_id < 2)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 2;
    }
    return _id;
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE

As it doesn't seem to get compiled, can probably be ignored, but maybe can be treated as an include.

TeLLie

  • Full Member
  • ***
  • Posts: 241
  • Karma: +12/-0
    • View Profile
Re: Duplicate symbol error
« Reply #6 on: October 01, 2023, 10:54:21 am »
Hi Dave,
Did you look at the old ported smplayer sources by BWW, how they did it there, probably a lot off diff changes...
But you never know :)

http://trac.netlabs.org/qtapps/browser/smplayer/trunk/src

Flashback

  • Newbie
  • *
  • Posts: 13
  • Karma: +4/-1
    • View Profile
Re: Duplicate symbol error
« Reply #7 on: October 01, 2023, 12:31:03 pm »
Code: [Select]
+       win32:os2 {
                HEADERS += winscreensaver.h
                SOURCES += winscreensaver.cpp
        }
Is that the correct way to add OS/2 support?

No. That means 'win32' AND 'os2', which doesn't make sense. What you want is 'win32' OR 'os2', which is expressed as:

Code: [Select]
win32|os2 {
  ...
}


Also: Why is "moc_screensaver.cpp" included in "screensaver.cpp"?  This is very odd. This file is generated and will be added to the Makefile automatically. Of course only, if qmake is run against a correct *.pro.

« Last Edit: October 01, 2023, 12:52:37 pm by Flashback »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #8 on: October 02, 2023, 01:28:15 am »
Hi Dave,
Did you look at the old ported smplayer sources by BWW, how they did it there, probably a lot off diff changes...
But you never know :)

http://trac.netlabs.org/qtapps/browser/smplayer/trunk/src

Thanks for the link, was wondering about the source as they changed from svn  to git and no old commits.
Silvan luckily got his patches committed so it is mostly a matter of bit rot. In the case of the screensaver support, when they added supported for turning off power management on *nix they moved the WIn32/OS/2 code from screensaver.cpp to winscreensaver.cpp. To my inexpert eye, the only real change is making the class QObject, at that seems most classes are QObject and I don't think that is the problem.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #9 on: October 02, 2023, 01:35:11 am »
Hi Flashback, thanks for the correction.
As for "moc_screensaver.cpp", all the source files seem to have moc_*.cpp included at the end of their files with the corresponding name of the cpp file. They're scattered through the generated Makefile

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2281
  • Karma: +176/-0
    • View Profile
Re: Duplicate symbol error
« Reply #10 on: October 02, 2023, 05:42:35 am »
Check smplayer.pro - screensaver.cpp  is being included twice

git diff @ https://smedley.id.au/tmp/smplayer.diff
smplayer.exe (untested) @ https://smedley.id.au/tmp/smplayer.zip
« Last Edit: October 02, 2023, 06:04:18 am by Paul Smedley »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5079
  • Karma: +117/-1
    • View Profile
Re: Duplicate symbol error
« Reply #11 on: October 02, 2023, 07:55:48 am »
Interesting that including it twice caused it. Builds here, crashes in Qt5pdf right away, so have to try to debug it.
Thanks