Unsolved one definition rule violations
-
Using Qt Creator on Ubuntu 16.04LTS, when building a project (for Release - Qt statically linked) I recently started getting a number of similar looking warnings:
/home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:181: warning: type ‘struct Function’ violates one definition rule [-Wodr] /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:181:46: warning: type ‘struct Function’ violates one definition rule [-Wodr] typedef Ret (Obj::*Function) (Args...); ^ .moc/qcolordialog.moc:112:57: note: a different type is defined in another translation unit /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:1749:41: note: the first difference of corresponding definitions is field ‘__pfn’ q->connect(custom, &QWellArray::colorChanged, [this] (int index, QRgb color) { ^ .moc/qcolordialog.moc:112:56: note: a field of same name but different type is defined in another translation unit lto1: note: type mismatch in parameter 1 /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:188:7: note: type ‘struct QWellArray’ defined in anonymous namespace can not match type ‘struct QWellArray’ class QWellArray : public QWidget ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:189:1: note: the incompatible type defined in anonymous namespace in another translation unit { ^
Any clues what might be causing them? FWIW - I don't know how/when exactly this started :-(
-
Please provide the link line for your project, also the part of the project file you have which relates to linking (i.e. link flags, modules, etc.).
-
I am using Qt Creator under Ubuntu 16.04LTS. AFAIK it does qmake followed by make. Qt is the latest v5 (5.15.2). Related project file content would be:
QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 [...] unix:!macx: LIBS += -L$$PWD/../../../openssl-OpenSSL_1_1_1j/ -lssl unix:!macx: LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/ -lusb-1.0 unix:!macx: INCLUDEPATH += $$PWD/../../../../../../usr/include/libusb-1.0 unix:!macx: DEPENDPATH += $$PWD/../../../../../../usr/include/libusb-1.0 unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../../usr/lib/x86_64-linux-gnu/libusb-1.0.a
-
You didn't supply the link line.
Also, no
CONFIG += static
? -
@kshegunov said in one definition rule violations:
You didn't supply the link line.
I am sorry but I don't know which line would that be. I see only
make
in the projects section of Qt Creator afterqmake
Also, no CONFIG += static?
No, should this be added? I don't remember ever adding that and static builds worked without those warnings for some time. I can try adding though if you recommend it.
-
@bogdan_bdg said in one definition rule violations:
I am sorry but I don't know which line would that be. I see only make in the projects section of Qt Creator after qmake
The line where the linker is invoked. That's under Creator's "Compile output" pane, it's probably the last full line, if you're not doing anything post-linkage. Should looks something like this:
g++ -Wl,-rpath-link, .... -o <application name> ...<object files + static libraries> -L... -l<dynamic libraries>
No, should this be added? I don't remember ever adding that and static builds worked without those warnings for some time. I can try adding though if you recommend it.
I think so, if not, one of the watchful Qt ninjas is going to correct me soon enough.
-
@kshegunov said in one definition rule violations:
That's under Creator's "Compile output" pane
Ah, from the output, not the config.. yes, here it comes:
g++ -Wl,-O1 -Wl,--gc-sections -fPIC -o Rasus_Update about.o bmaerasus.o main.o mainwindow.o scratch.o svffile.o udevdialog.o rasus_update_plugin_import.o qrc_Images.o moc_about.o moc_bmaerasus.o moc_mainwindow.o moc_svffile.o moc_udevdialog.o -L/home/bogdan/sources/bogdan/qt5/rasus_update/../../../openssl-OpenSSL_1_1_1j/ -L/home/bogdan/sources/bogdan/qt5/rasus_update/../../../../../../usr/lib/x86_64-linux-gnu/ -lusb-1.0 /home/bogdan/Qt/5.15.2-static/plugins/platforms/libqxcb.a -L/home/bogdan/sources/openssl-OpenSSL_1_1_1j/ /home/bogdan/Qt/5.15.2-static/plugins/xcbglintegrations/libqxcb-glx-integration.a /home/bogdan/Qt/5.15.2-static/lib/libQt5XcbQpa.a /home/bogdan/Qt/5.15.2-static/lib/libQt5ServiceSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5ThemeSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5FontDatabaseSupport.a -lfontconfig -lfreetype /home/bogdan/Qt/5.15.2-static/lib/libQt5XkbCommonSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5GlxSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5EdidSupport.a -lxcb-glx -lX11-xcb -lxcb-icccm -lxcb-image -lxcb-shm -lxcb-util -lxcb-keysyms -lxcb-randr -lxcb-render-util -lxcb-sync -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb-xinerama -lxcb-xkb -lxcb -lXext -lX11 -lxkbcommon-x11 -lxkbcommon /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqgif.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqicns.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqico.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqjpeg.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqtga.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqtiff.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqwbmp.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqwebp.a /home/bogdan/Qt/5.15.2-static/plugins/bearer/libqconnmanbearer.a /home/bogdan/Qt/5.15.2-static/plugins/bearer/libqgenericbearer.a /home/bogdan/Qt/5.15.2-static/plugins/bearer/libqnmbearer.a /home/bogdan/Qt/5.15.2-static/lib/libQt5DBus.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Widgets.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Gui.a -lpng12 /home/bogdan/Qt/5.15.2-static/lib/libqtharfbuzz.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Network.a -lssl -lcrypto /home/bogdan/Qt/5.15.2-static/lib/libQt5Core.a -lm -lz /home/bogdan/Qt/5.15.2-static/lib/libqtpcre2.a -ldl -lGL -lpthread
adding "static" to config didn't change anything.
-
Looks okay. What gets me is that the errors you get are coming from the Qt's sources - like if you're linking Qt itself, which is very odd. I wouldn't have expected you to get these once the
.a
is generated ...Can you try this with a minimal application to demonstrate (i.e. a dummy test case)?
-
@kshegunov said in one definition rule violations:
Can you try this with a minimal application to demonstrate (i.e. a dummy test case)?
OK, I'll try to replicate this on a minimal application (fingers crossed :-) and get back.
-
Is your g++ too old? what is g++ version in your 16? Qt-5.15.2 could be too new for the g++ on 16. The g++ of 18 on my machine is 7.5 and pretty old.
-
@JoeCFD said in one definition rule violations:
Is your g++ too old? what is g++ version in your 16? Qt-5.15.2 could be too new for the g++ on 16. The g++ of 18 on my machine is 7.5 and pretty old.
$ g++ --version g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
@JoeCFD said in one definition rule violations:
Is your g++ too old? what is g++ version in your 16? Qt-5.15.2 could be too new for the g++ on 16. The g++ of 18 on my machine is 7.5 and pretty old.
Hm... but i think it worked before <something>
-
@bogdan_bdg said in one definition rule violations:
@kshegunov said in one definition rule violations:
Can you try this with a minimal application to demonstrate (i.e. a dummy test case)?
OK, I'll try to replicate this on a minimal application (fingers crossed :-) and get back.
Set a bare minimal project using Qt Creator up:
https://www.dropbox.com/s/gwo5jczod4nrghj/minimal.tar.bz2
And it does exhibit the issue too.
Less than in the real project, probably because it uses less modules, but it even the "core" has problems
-
The code looks correct, and these files haven't been changed since 2013, so please paste here the whole of the build output from creator's pane (I neither have a static Qt nor a compiler this old).
-
Here it goes (thank you very much for your willingness to have a look at it):
12:40:02: Running steps for project minimal... 12:40:02: Starting: "/home/bogdan/Qt/5.15.2-static/bin/qmake" /home/bogdan/sources/bogdan/qt5/minimal/minimal/minimal.pro -spec linux-g++ CONFIG+=qtquickcompiler Info: creating stash file /home/bogdan/sources/bogdan/qt5/minimal/build-minimal-Desktop_Qt_5_15_2_static-Release/.qmake.stash 12:40:02: The process "/home/bogdan/Qt/5.15.2-static/bin/qmake" exited normally. 12:40:02: Starting: "/usr/bin/make" -f /home/bogdan/sources/bogdan/qt5/minimal/build-minimal-Desktop_Qt_5_15_2_static-Release/Makefile qmake_all make: Nothing to be done for 'qmake_all'. 12:40:02: The process "/usr/bin/make" exited normally. 12:40:02: Starting: "/usr/bin/make" -j6 /home/bogdan/Qt/5.15.2-static/bin/uic ../minimal/mainwindow.ui -o ui_mainwindow.h g++ -c -pipe -O2 -std=gnu++11 -Wall -Wextra -ffunction-sections -fdata-sections -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../minimal -I. -I/home/bogdan/Qt/5.15.2-static/include -I/home/bogdan/Qt/5.15.2-static/include/QtWidgets -I/home/bogdan/Qt/5.15.2-static/include/QtGui -I/home/bogdan/Qt/5.15.2-static/include/QtCore -I. -I/usr/include/libdrm -I. -I/home/bogdan/Qt/5.15.2-static/mkspecs/linux-g++ -o main.o ../minimal/main.cpp g++ -c -pipe -O2 -std=gnu++11 -Wall -Wextra -ffunction-sections -fdata-sections -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../minimal -I. -I/home/bogdan/Qt/5.15.2-static/include -I/home/bogdan/Qt/5.15.2-static/include/QtWidgets -I/home/bogdan/Qt/5.15.2-static/include/QtGui -I/home/bogdan/Qt/5.15.2-static/include/QtCore -I. -I/usr/include/libdrm -I. -I/home/bogdan/Qt/5.15.2-static/mkspecs/linux-g++ -o mainwindow.o ../minimal/mainwindow.cpp g++ -c -pipe -O2 -std=gnu++11 -Wall -Wextra -ffunction-sections -fdata-sections -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../minimal -I. -I/home/bogdan/Qt/5.15.2-static/include -I/home/bogdan/Qt/5.15.2-static/include/QtWidgets -I/home/bogdan/Qt/5.15.2-static/include/QtGui -I/home/bogdan/Qt/5.15.2-static/include/QtCore -I. -I/usr/include/libdrm -I. -I/home/bogdan/Qt/5.15.2-static/mkspecs/linux-g++ -o minimal_plugin_import.o /home/bogdan/sources/bogdan/qt5/minimal/build-minimal-Desktop_Qt_5_15_2_static-Release/minimal_plugin_import.cpp g++ -pipe -O2 -std=gnu++11 -Wall -Wextra -ffunction-sections -fdata-sections -dM -E -o moc_predefs.h /home/bogdan/Qt/5.15.2-static/mkspecs/features/data/dummy.cpp /home/bogdan/Qt/5.15.2-static/bin/moc -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB --include /home/bogdan/sources/bogdan/qt5/minimal/build-minimal-Desktop_Qt_5_15_2_static-Release/moc_predefs.h -I/home/bogdan/Qt/5.15.2-static/mkspecs/linux-g++ -I/home/bogdan/sources/bogdan/qt5/minimal/minimal -I/home/bogdan/Qt/5.15.2-static/include -I/home/bogdan/Qt/5.15.2-static/include/QtWidgets -I/home/bogdan/Qt/5.15.2-static/include/QtGui -I/home/bogdan/Qt/5.15.2-static/include/QtCore -I. -I/usr/include/c++/5 -I/usr/include/x86_64-linux-gnu/c++/5 -I/usr/include/c++/5/backward -I/usr/lib/gcc/x86_64-linux-gnu/5/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include ../minimal/mainwindow.h -o moc_mainwindow.cpp g++ -c -pipe -O2 -std=gnu++11 -Wall -Wextra -ffunction-sections -fdata-sections -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../minimal -I. -I/home/bogdan/Qt/5.15.2-static/include -I/home/bogdan/Qt/5.15.2-static/include/QtWidgets -I/home/bogdan/Qt/5.15.2-static/include/QtGui -I/home/bogdan/Qt/5.15.2-static/include/QtCore -I. -I/usr/include/libdrm -I. -I/home/bogdan/Qt/5.15.2-static/mkspecs/linux-g++ -o moc_mainwindow.o moc_mainwindow.cpp g++ -Wl,-O1 -Wl,--gc-sections -fPIC -o minimal main.o mainwindow.o minimal_plugin_import.o moc_mainwindow.o /home/bogdan/Qt/5.15.2-static/plugins/platforms/libqxcb.a -L/home/bogdan/sources/openssl-OpenSSL_1_1_1j/ /home/bogdan/Qt/5.15.2-static/plugins/xcbglintegrations/libqxcb-glx-integration.a /home/bogdan/Qt/5.15.2-static/lib/libQt5XcbQpa.a /home/bogdan/Qt/5.15.2-static/lib/libQt5ServiceSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5ThemeSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5FontDatabaseSupport.a -lfontconfig -lfreetype /home/bogdan/Qt/5.15.2-static/lib/libQt5XkbCommonSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5GlxSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5EdidSupport.a /home/bogdan/Qt/5.15.2-static/lib/libQt5DBus.a -lxcb-glx -lX11-xcb -lxcb-icccm -lxcb-image -lxcb-shm -lxcb-util -lxcb-keysyms -lxcb-randr -lxcb-render-util -lxcb-sync -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb-xinerama -lxcb-xkb -lxcb -lXext -lX11 -lxkbcommon-x11 -lxkbcommon /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqgif.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqicns.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqico.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqjpeg.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqtga.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqtiff.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqwbmp.a /home/bogdan/Qt/5.15.2-static/plugins/imageformats/libqwebp.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Widgets.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Gui.a -lpng12 /home/bogdan/Qt/5.15.2-static/lib/libqtharfbuzz.a /home/bogdan/Qt/5.15.2-static/lib/libQt5Core.a -lm -lz /home/bogdan/Qt/5.15.2-static/lib/libqtpcre2.a -ldl -lGL -lpthread /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:181:46: warning: type ‘struct Function’ violates one definition rule [-Wodr] typedef Ret (Obj::*Function) (Args...); ^ .moc/qcolordialog.moc:112:57: note: a different type is defined in another translation unit /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:1749:41: note: the first difference of corresponding definitions is field ‘__pfn’ q->connect(custom, &QWellArray::colorChanged, [this] (int index, QRgb color) { ^ .moc/qcolordialog.moc:112:56: note: a field of same name but different type is defined in another translation unit lto1: note: type mismatch in parameter 1 /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:188:7: note: type ‘struct QWellArray’ defined in anonymous namespace can not match type ‘struct QWellArray’ class QWellArray : public QWidget ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/widgets/dialogs/qcolordialog.cpp:189:1: note: the incompatible type defined in anonymous namespace in another translation unit { ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/plugins/imageformats/ico/qicohandler.cpp:95:3: warning: type ‘struct BMP_INFOHDR’ violates one definition rule [-Wodr] } BMP_INFOHDR ,*LPBMP_INFOHDR; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtGui/5.15.2/QtGui/private/../../../../../src/gui/image/qbmphandler_p.h:69:8: note: a different type is defined in another translation unit struct BMP_INFOHDR { // BMP information header ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/plugins/imageformats/ico/qicohandler.cpp:84:16: note: the first difference of corresponding definitions is field ‘biSize’ quint32_le biSize; // size of this struct ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtGui/5.15.2/QtGui/private/../../../../../src/gui/image/qbmphandler_p.h:70:13: note: a field of same name but different type is defined in another translation unit qint32 biSize; // size of this struct ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/../../src/corelib/global/qendian.h:426:29: note: type ‘struct quint32_le’ should match type ‘qint32’ typedef QLEInteger<quint32> quint32_le; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:237:13: note: the incompatible type is defined here typedef int qint32; /* 32 bit signed */ ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:165:16: warning: type ‘struct HB_FaceRec_’ violates one definition rule [-Wodr] typedef struct HB_FaceRec_ { ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-shaper.h:191:16: note: a different type is defined in another translation unit typedef struct HB_FaceRec_ { ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:168:13: note: the first difference of corresponding definitions is field ‘gdef’ HB_GDEF gdef; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-shaper.h:194:13: note: a field of same name but different type is defined in another translation unit HB_GDEF gdef; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:158:16: note: type ‘void *’ should match type ‘struct HB_GDEFHeader_ *’ typedef void * HB_GDEF; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-gdef.h:107:33: note: the incompatible type is defined here typedef struct HB_GDEFHeader_* HB_GDEF; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:240:8: warning: type ‘struct HB_ShaperItem_’ violates one definition rule [-Wodr] struct HB_ShaperItem_ { ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-shaper.h:250:8: note: a different type is defined in another translation unit struct HB_ShaperItem_ { ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:245:13: note: the first difference of corresponding definitions is field ‘face’ HB_Face face; /* input: the shaper state; current script, access to the OpenType tables , etc. */ ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-shaper.h:255:13: note: a field of same name but different type is defined in another translation unit HB_Face face; /* input: the shaper state; current script, access to the OpenType tables , etc. */ ^ /home/bogdan/Qt/5.15.2/Src/qtbase/include/QtCore/5.15.2/QtCore/private/../../../../../src/corelib/text/qharfbuzz_p.h:197:29: note: type ‘struct HB_FaceRec_ *’ should match type ‘struct HB_FaceRec_ *’ typedef struct HB_FaceRec_ *HB_Face; ^ /home/bogdan/Qt/5.15.2/Src/qtbase/src/3rdparty/harfbuzz/src/harfbuzz-global.h:114:29: note: the incompatible type is defined here typedef struct HB_FaceRec_ *HB_Face; ^ 12:43:46: The process "/usr/bin/make" exited normally. 12:43:46: Elapsed time: 03:44.
-
I hoped to find something wrong, but I couldn't spot anything. I understand what the error means, but for the life of me can't tell why you get it.
Can you try with a different compiler? A newer one?
-
I apologise for the delay in response... the answer is I don't know. Obviously I can try installing packets from newer distro version but I am afraid this can open can of worms (been there, seen that) inside a well behaving installation, which only very recently became no longer supported. Shall have to make a full backup so that I don't end-up with a broken machine.