Qt library compilation error: qmutex_linux.cpp: multiple definition of 'QBasicMutex :: lockInternal (int)'

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.cppfollowing 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.prifollowing 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.cppincluded 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.prifile, SOURCESfor qmutex_linux.cppexample:

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
}
Published 32 original articles · won praise 1 · views 4551

Guess you like

Origin blog.csdn.net/hezhanran/article/details/105053187