wrong description
.obj/qmutex_linux.o: In function QBasicMutex::lockInternal()': qmutex_linux.cpp:(.text+0x0): multiple definition ofQBasicMutex::lockInternal()'
.obj/qmutex.o:qmutex.cpp:(.text+0x150): first defined here
.obj/qmutex_linux.o: In function QBasicMutex::lockInternal(int)': qmutex_linux.cpp:(.text+0x60): multiple definition ofQBasicMutex::lockInternal(int)'
.obj/qmutex.o:qmutex.cpp:(.text+0x2a8): first defined here
.obj/qmutex_linux.o: In function QBasicMutex::unlockInternal()': qmutex_linux.cpp:(.text+0x1e0): multiple definition ofQBasicMutex::unlockInternal()'
.obj/qmutex.o:qmutex.cpp:(.text+0x550): first defined here
collect2: error: ld returned 1 exit status
Makefile:1241: recipe for target '../../lib/libQt5Core.so.5.13.0' failed
make[3]: *** [../../lib/libQt5Core.so.5.13.0] Error 1
make[3]: Leaving directory '/home/firefly/Downloads/build_qt/qtbase/src/corelib'
Makefile:226: recipe for target 'sub-corelib-make_first' failed
make[2]: *** [sub-corelib-make_first] Error 2
make[2]: Leaving directory '/home/firefly/Downloads/build_qt/qtbase/src'
Makefile:50: recipe for target 'sub-src-make_first' failed
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory '/home/firefly/Downloads/build_qt/qtbase'
Makefile:63: recipe for target 'module-qtbase-make_first' failed
make: *** [module-qtbase-make_first] Error 2
wrong reason
This is due to the qtbase/src/corelib/thread/qmutex.cpp
following code in the source file :
#ifdef QT_LINUX_FUTEX
# include "qmutex_linux.cpp"
#elif defined(Q_OS_MAC)
# include "qmutex_mac.cpp"
#elif defined(Q_OS_WIN)
# include "qmutex_win.cpp"
#else
# include "qmutex_unix.cpp"
#endif
This is to be compatible with code from different platforms. But the qtbase/src/corelib/thread/thread.pri
following code is also included in the project file :
SOURCES += \
thread/qatomic.cpp \
thread/qmutex.cpp \
thread/qreadwritelock.cpp \
thread/qsemaphore.cpp \
thread/qthreadpool.cpp \
thread/qthreadstorage.cpp
win32 {
SOURCES += \
thread/qmutex_win.cpp \
thread/qwaitcondition_win.cpp
} else {
darwin {
SOURCES += thread/qmutex_mac.cpp
} else: linux {
SOURCES += thread/qmutex_linux.cpp
} else {
SOURCES += thread/qmutex_unix.cpp
}
SOURCES += thread/qwaitcondition_unix.cpp
}
These two places qmutex_linux.cpp
included files repeatedly, so it caused the same symbol in both files during compilation.
Solution
You can delete references to the qtbase/src/corelib/thread/thread.pri
file, SOURCES
for qmutex_linux.cpp
example:
SOURCES += \
thread/qatomic.cpp \
thread/qmutex.cpp \
thread/qreadwritelock.cpp \
thread/qsemaphore.cpp \
thread/qthreadpool.cpp \
thread/qthreadstorage.cpp
win32 {
SOURCES += \
thread/qmutex_win.cpp \ /* 手动删除本行 */
thread/qwaitcondition_win.cpp
} else {
darwin {
SOURCES += thread/qmutex_mac.cpp /* 手动删除本行 */
} else: linux {
SOURCES += thread/qmutex_linux.cpp /* 手动删除本行 */
} else {
SOURCES += thread/qmutex_unix.cpp /* 手动删除本行 */
}
SOURCES += thread/qwaitcondition_unix.cpp
}