FreeSpacenav / spnavcfg

Spacenav interactive configuration GUI
GNU General Public License v3.0
59 stars 16 forks source link

[1.1] Fails to build with link error "multiple definition of [..]" #29

Closed hartwork closed 1 year ago

hartwork commented 1 year ago

Hi!

I'm running into link errors with release 1.1 is this known?

To reproduce:

# cd "$(mktemp -d)"

# wget https://github.com/FreeSpacenav/spnavcfg/releases/download/v1.1/spnavcfg-1.1.tar.gz

# tar xf spnavcfg-1.1.tar.gz 

# cd spnavcfg-1.1/

# ls -l icons/devices.png | sed "s,${USER},user,g"
-rw-r--r-- 1 user user 287656 30. Nov 23:46 icons/devices.png

# ./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --libdir=/usr/lib64 --disable-debug --disable-opt
configuring spnavcfg...
  prefix: /usr
  optimize for speed: no
  include debugging symbols: no

creating Makefile ...

Done. You can now type make (or gmake) to compile spnavcfg.

# make -j1 CC=x86_64-pc-linux-gnu-gcc CXX=x86_64-pc-linux-gnu-g++ MOC=/usr/lib64/qt5/bin/moc RCC=/usr/lib64/qt5/bin/rcc UIC=/usr/lib64/qt5/bin/uic libpath=-L/usr/lib64
x86_64-pc-linux-gnu-gcc -pedantic -Wall   -I. -I/usr/include -fPIC  -MMD   -c -o src/spnavcfg.o src/spnavcfg.c
x86_64-pc-linux-gnu-g++ -std=c++11 -pedantic -Wall   -I. -I/usr/include -fPIC `pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets`  -MMD   -c -o src/main.o src/main.cc
/usr/lib64/qt5/bin/uic -o ui_mainwin.h ui/spnavcfg.ui
/usr/lib64/qt5/bin/uic -o ui_bnmaprow.h ui/bnmaprow.ui
/usr/lib64/qt5/bin/uic -o ui_about.h ui/about.ui
x86_64-pc-linux-gnu-g++ -std=c++11 -pedantic -Wall   -I. -I/usr/include -fPIC `pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets`  -MMD   -c -o src/ui.o src/ui.cc
/usr/lib64/qt5/bin/moc -o src/ui.moc.cc -I. -I/usr/include src/ui.h
x86_64-pc-linux-gnu-g++ -std=c++11 -pedantic -Wall   -I. -I/usr/include -fPIC `pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets`  -MMD   -c -o src/ui.moc.o src/ui.moc.cc
/usr/lib64/qt5/bin/rcc -o res.cc ui/spnavcfg.qrc
x86_64-pc-linux-gnu-g++ -o spnavcfg src/spnavcfg.o src/main.o src/ui.o src/ui.moc.o src/ui.moc.o res.cc -L/usr/lib64 `pkg-config --libs Qt5Core Qt5Gui Qt5Widgets` -lspnav -lX11 
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: src/ui.moc.o: in function `MainWin::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':
ui.moc.cc:(.text+0x0): multiple definition of `MainWin::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)'; src/ui.moc.o:ui.moc.cc:(.text+0x0): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: src/ui.moc.o:(.data.rel.ro+0x0): multiple definition of `MainWin::staticMetaObject'; src/ui.moc.o:(.data.rel.ro+0x0): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: src/ui.moc.o: in function `MainWin::metaObject() const':
ui.moc.cc:(.text+0x162): multiple definition of `MainWin::metaObject() const'; src/ui.moc.o:ui.moc.cc:(.text+0x162): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: src/ui.moc.o: in function `MainWin::qt_metacast(char const*)':
ui.moc.cc:(.text+0x1aa): multiple definition of `MainWin::qt_metacast(char const*)'; src/ui.moc.o:ui.moc.cc:(.text+0x1aa): first defined here
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: src/ui.moc.o: in function `MainWin::qt_metacall(QMetaObject::Call, int, void**)':
ui.moc.cc:(.text+0x1fe): multiple definition of `MainWin::qt_metacall(QMetaObject::Call, int, void**)'; src/ui.moc.o:ui.moc.cc:(.text+0x1fe): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:27: spnavcfg] Error 1
rm src/ui.moc.cc

This is with GCC 11.3.1 and Qt 5.15.7 if it matters.

Any ideas for a fix?

Best, Sebastian

hartwork commented 1 year ago

PS: I just found this patch in Arch AUR. It seems to work: https://aur.archlinux.org/cgit/aur.git/tree/Makefile.in.diff?h=spnavcfg

jtsiomb commented 1 year ago

Are you sure you didn't change something else between attempts? That patch simply changes the order of object files in the makefile. Doing that should make absolutely no difference.

hartwork commented 1 year ago

@jtsiomb I am 100% sure, yes. I believe the key is "removing duplicate words", see https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#index-sort and the "Fix linker problem caused by duplicate object file" commit message at https://aur.archlinux.org/cgit/aur.git/commit/Makefile.in.diff?h=spnavcfg&id=7daaa4a5ca4a10ea6d7e3067c556f57bd6370133 .

jtsiomb commented 1 year ago

Ok I see what's going on. The problem is with the generated src/ui.moc.cc file which is added explicitly to the obj list, because it does not exist before the build starts.

If for some reason that file exists before starting the build, it will also be picked up by the wildcard, and therefore added twice to the list. The problem is I don't see how it could possibly exist before starting the build...

jtsiomb commented 1 year ago

Anyway, this is a good stopgap. I wish I had the time to figure out why this happens and fix it properly, but for now this will do.

edit: btw I can't reproduce here. I still only see one copy of ui.moc.o in the linker command line here.

hartwork commented 1 year ago

Thanks. Maybe it has to do with the version of GNU make. Arch and me both have GNU make 4.4.