简体   繁体   English

QT Subdir-未定义参考

[英]QT Subdir - Undefined Reference

I am working on a QT project with subdirs, it works just fine on linux (ubuntu) but when I tried to run on windows I get undefinded reference to `moduleInterface::...´ in which ... refers to all the methods on my subdir. 我正在使用带有子目录的QT项目,它在linux(ubuntu)上运行良好,但是当我尝试在Windows上运行时,我得到了对`moduleInterface :: ...'的未定义引用 ,其中...表示所有方法在我的子目录上。 The Qt version I am using (5.11.2) is the same in both linux and windows. 我使用的Qt版本(5.11.2)在Linux和Windows中都是相同的。 The subdirs configurations are the following: 子目录配置如下:

main.pro main.pro

TEMPLATE = subdirs

SUBDIRS += \
         tests \
         coreSerialTerm \
         serialTermView

serialTermView.depends = coreSerialTerm
tests.depends = coreSerialTerm

coreSerialTerm.pro coreSerialTerm.pro

QT       -= gui
QT       += serialport
QT       += core
CONFIG   += c++14
TARGET = coreSerialTerm
TEMPLATE = lib

DEFINES += CORESERIALTERM_LIBRARY

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs. 
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version     of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs   deprecated before Qt 6.0.0

SOURCES += \
         coreserialterm.cpp \
         serialInterface/serialinterface.cpp \
         moduleInterface/moduleinterface.cpp \
         serialProtocol/serialProtocol.c \
         moduleInterface/progressbar.cpp \
         agroflashinterface.cpp \
         Storage/event_list.c \
         Storage/storage.c \
         flashfilehandler.cpp

HEADERS += \
    coreserialterm.h \
    coreserialterm_global.h \ 
   serialInterface/serialinterface.h \
moduleInterface/moduleinterface.h \
serialProtocol/serialProtocol.h \
devRetCode.h \
moduleInterface/progressbar.h \
Sensors/sensor.h \
Storage/storage.h \
Utils/configManager.h \
Utils/configStates.h \
Utils/delayPlus.h \
Utils/io.h \
Utils/rtcManager.h \
Utils/wdg.h \
version.h \
module.h \
flashfilehandler.h

serialTermView.pro serialTermView.pro

QT       += core gui
QT       += serialport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = serialTermView
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the 
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs. 
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
       main.cpp \
       mainwindow.cpp

HEADERS += \
       mainwindow.h

FORMS += \
       mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../coreSerialTerm/release/ -lcoreSerialTerm
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../coreSerialTerm/debug/ -lcoreSerialTerm
else:unix: LIBS += -L$$OUT_PWD/../coreSerialTerm/ -lcoreSerialTerm

INCLUDEPATH += $$PWD/../coreSerialTerm
DEPENDPATH += $$PWD/../coreSerialTerm

When I compile, I get the following errors : 编译时,出现以下错误:

debug/mainwindow.o: In function `ZN10MainWindowC2EP7QWidget':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:13: undefined reference to `flashFileHandler::flashFileHandler()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:18: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:18: undefined reference to `moduleInterface::availablePorts()'
debug/mainwindow.o: In function `operator()':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:58: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:58: undefined reference to `moduleInterface::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:65: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:65: undefined reference to `moduleInterface::close()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:106: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:106: undefined reference to `moduleInterface::getTime(unsigned int*)'
debug/mainwindow.o: In function `ZN10MainWindow7getTimeEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:98: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:98: undefined reference to `moduleInterface::isConnected()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:138: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:138: undefined reference to `moduleInterface::close()'
debug/mainwindow.o: In function `operator()':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:163: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:163: undefined reference to `moduleInterface::setTime()'
debug/mainwindow.o: In function `ZN10MainWindow7setTimeEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:148: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:148: undefined reference to `moduleInterface::isConnected()'
debug/mainwindow.o: In function `operator()':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:229: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:229: undefined reference to `moduleInterface::memoryDump(unsigned char*, unsigned int)'
debug/mainwindow.o: In function `ZN10MainWindow7memDumpEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:210: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:210: undefined reference to `moduleInterface::isConnected()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:226: undefined reference to `moduleInterface::pageChanged(int)'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:223: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:261: undefined reference to `moduleInterface::Instance()'
debug/mainwindow.o: In function `ZN10MainWindow6saveAsEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:279: undefined reference to `flashFileHandler::open(QString)'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:281: undefined reference to `flashFileHandler::save(QString)'
debug/mainwindow.o: In function `ZN10MainWindow4saveEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:288: undefined reference to `flashFileHandler::isReady()'
debug/mainwindow.o: In function `ZN10MainWindow9closePortEv':
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:297: undefined reference to `moduleInterface::Instance()'
C:\Users\Augusto\Documents\Workspace\serialTerm\build-serialTerm-Desktop_Qt_5_11_2_MinGW_32bit-Debug\serialTermView/../../serialTerm/serialTermView/mainwindow.cpp:297: undefined reference to `moduleInterface::close()'
debug/mainwindow.o: In function `connect<void (moduleInterface::*)(int), MainWindow::memDump()::<lambda(int)> >':
C:/Qt/5.11.2/mingw53_32/include/QtCore/qobject.h:333: undefined reference to `moduleInterface::staticMetaObject'
collect2.exe: error: ld returned 1 exit status

It looks like a compiling order problem. 它看起来像一个编译顺序问题。 Probably the linker can't find some symbols because they belong to one of the other sub-projects, but they have not been processed yet. 链接器可能找不到某些符号,因为它们属于其他子项目之一,但尚未处理。

Try to change your subdirs .pro file as follows: 尝试如下更改您的subdirs .pro文件:

TEMPLATE = subdirs

CONFIG += ordered

SUBDIRS += \             
         coreSerialTerm \
         tests \
         serialTermView

The .depends attribute never really worked for me on windows. .depends属性从未真正在Windows上对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM