error: undefined reference to
-
Hello friends.
I come here because of the problem described in the title of the message.
I know there are many references to this problem in this forum and in many others. You have done all the solutions presented in each topic that you have reviewed but it has not helped me to solve and / or understand the why? Of my problem
I have the following project, structured in subdirectories project:
Ecomoditorgui/ecomoditorgui.pro // Sub-directories project Ecomoditorgui/com/com.pro // Sub-directories project Ecomoditorgui/com/ecosoftware/ecosoftware.pro // Sub-directories project Ecomoditorgui/com/ecosoftware/app/app.pro // Shared library Ecomoditorgui/com/ecosoftware/window/window.pro // Sub subdirectories project Ecomoditorgui/com/ecosoftware/window/mainwindow/mainwindow.pro // Shared library Ecomoditorgui/examples/examples.pro // Sub-directories project Ecomoditorgui/examples/maingui / maingui.pro // Test executable
Now, these are the .pro of each subproject.
ecomoditorgui/ecomoditorgui.pro TEMPLATE = subdirs CONFIG += ordered UI_DIR = ui SUBDIRS += \ com \ examples examples.depends = com ecomoditorgui/com/com.pro TEMPLATE = subdirs UI_DIR = ../ui SUBDIRS += \ ecosoftware ecomoditorgui/com/ecosoftware/ecosoftware.pro TEMPLATE = subdirs CONFIG += ordered UI_DIR = ../../ui SUBDIRS += \ app \ window window.depends = app ecomoditorgui/com/ecosoftware/app/app.pro QT -= gui CONFIG += c++14 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets core xml xmlpatterns TARGET = app TEMPLATE = lib DESTDIR = ../ UI_DIR = ../../../ui DEFINES += APP_LIBRARY DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ AppInfo.cpp \ AppInit.cpp \ AppSettings.cpp \ AppUtils.cpp \ AppPaths.cpp HEADERS += \ app_global.h \ AppInfo.h \ AppInit.h \ AppSettings.h \ AppUtils.h \ AppPaths.h unix { target.path = /usr/lib INSTALLS += target } ecomoditorgui/com/ecosoftware/window/window.pro TEMPLATE = subdirs CONFIG += ordered UI_DIR = ../../../ui SUBDIRS += \ mainwindow ecomoditorgui/com/ecosoftware/window/mainwindow/mainwindow.pro QT -= gui CONFIG += c++14 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = mainwindow TEMPLATE = lib DESTDIR = ../ UI_DIR = ../../../../ui DEFINES += MAINWINDOW_LIBRARY DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ MainWindow.cpp \ MainWindowActions.cpp \ MainWindowEvents.cpp \ MainWindowSignals.cpp \ MainWindowSlots.cpp HEADERS += \ mainwindow_global.h \ MainWindow.h \ MainWindowActions.h \ MainWindowEvents.h \ MainWindowSignals.h \ MainWindowSlots.h unix { target.path = /usr/lib INSTALLS += target } win32:CONFIG(release, debug|release): LIBS += \ -L$$OUT_PWD/../../app/release/ -lapp else:win32:CONFIG(debug, debug|release): LIBS += \ -L$$OUT_PWD/../../app/debug/ -lapp else:unix: LIBS += \ -L$$OUT_PWD/../../ -lapp INCLUDEPATH += \ $$PWD/../../app DEPENDPATH += \ $$PWD/../../app ecomoditorgui/examples/examples.pro TEMPLATE = subdirs SUBDIRS += \ maingui ecomoditorgui/examples/maingui/maingui.pro CONFIG += c++14 greaterThan(QT_MAJOR_VERSION, 4): QT += core gui widgets core xml xmlpatterns TARGET = mainecomoditorgui TEMPLATE = app DESTDIR = ../ UI_DIR = ../../../ui DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ MainWindowGui.cpp HEADERS += \ MainWindowGui.h win32:CONFIG(release, debug|release): LIBS += \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow else:win32:CONFIG(debug, debug|release): LIBS += \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow else:unix: LIBS += \ -L$$OUT_PWD/../../com/ecosoftware/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow INCLUDEPATH += \ ../../ui \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow DEPENDPATH += \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow
I have simplified the whole project which is much more extensive, only to reproduce the error with the minimum possible code, so that they can check it more easily and can make a manito to me as much as possible.
The errors that are presented to me are the following (although in fact it is the same):
/home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/MainWindowGui.o:-1: In function `Com::Ecosoftware::Ecomoditor::Examples::Maingui::MainWindowGui::MainWindowGui(QWidget*)': /home/remizero/Proyectos/Qt/ecomoditorgui/examples/maingui/MainWindowGui.cpp:7: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::MainWindow(QWidget*)' /home/remizero/Proyectos/Qt/ecomoditorgui/examples/maingui/MainWindowGui.cpp:7: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::~MainWindow()' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/MainWindowGui.o:-1: In function `Com::Ecosoftware::Ecomoditor::Examples::Maingui::MainWindowGui::~MainWindowGui()': /home/remizero/Proyectos/Qt/ecomoditorgui/examples/maingui/MainWindowGui.cpp:17: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::~MainWindow()' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.o:-1: In function `Com::Ecosoftware::Ecomoditor::Examples::Maingui::MainWindowGui::qt_metacast(char const*)': /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.cpp:93: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::qt_metacast(char const*)' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.o:-1: In function `Com::Ecosoftware::Ecomoditor::Examples::Maingui::MainWindowGui::qt_metacall(QMetaObject::Call, int, void**)': /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.cpp:98: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::qt_metacall(QMetaObject::Call, int, void**)' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.o:-1: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::staticMetaObject' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.o:-1: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::resizeEvent(QResizeEvent*)' /home/remizero/Proyectos/Qt/ecomoditorgui-Debug/examples/maingui/moc_MainWindowGui.o:-1: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::closeEvent(QCloseEvent*)' moc_MainWindowGui.o:-1: error: undefined reference to `Com::Ecosoftware::Window::MainWindow::MainWindow::changeEvent(QEvent*)' moc_MainWindowGui.o:-1: error: undefined reference to `typeinfo for Com::Ecosoftware::Window::MainWindow::MainWindow' :-1: error: collect2: error: ld returned 1 exit status
I understand that all these errors are presented at the linker level.
But I have already tried a huge amount of solutions exposed in this forum and many others but none has helped me to solve the problem.
They could tell me that doing this wrong!;).It should be noted that this project has already been fully done and it works. But of course I have it just as a static application, but the problem is that it weighs a lot and for large projects like those that development consumes many resources. Because I have decided to restructure it to work with shared libraries and thus reuse the code more dynamically and on demand and reduce resource consumption that makes me quite expensive in some teams with few resources.
If you need any additional code let me know and I will gladly upload it. I do not know how to upload the code to the forum, but I leave this link to my account in mega so that they download it and they can try and see that I am doing wrong, if that was so.
I'm working on Debian 9 64bit, QtCreator 4.2.0 and Qt 5.7.1
https://mega.nz/#!eIY32DDT!QTK5jIXBr1pRu7T3WrRg6T5UXkvpghkPeNBYNEwstNk
Thanks in advance.
-
Thanks for your prompt response.
Hi @SGaist, that line automatically places the QtCreator, so I only leave it there because it allows me to add the additional Qt modules that I require, when I require clear is jejeje.
Hi @ambershark. Well, taking into account what you told me, has made a more exhaustive review of my files.
LIBS + = -L../../com/ecosoftware/window -lmainwindow
I still had a question about why? It did not work correctly if indeed that line that your comments are included in the LIBS variable for all platforms.
Well, I realized that by doing tests on tests, I was not looking for the backslash at the end of the last included library.
The funniest thing about everything is for the code published in the post, if it worked, then the correct thing, but in the code that is in the attachment, I left it as it was in the tests and that's where it can be appreciated The error
For example, attachment with the error:
Win32: CONFIG (release, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \ Else: win32: CONFIG (debug, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \ Else: unix: LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/ -app \ -L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow \ INCLUDEPATH + = \ ../../ui \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow DEPENDPATH + = \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow
Correct form of the file, correcting the error:
Win32: CONFIG (release, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow Else: win32: CONFIG (debug, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow Else: unix: LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/ -app \ -L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow INCLUDEPATH + = \ ../../ui \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow DEPENDPATH + = \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow
Thank you very much for your help, I hereby solve this thread. I hope this explanation will help others identify the why? Of this error when they only work with qmake.
-
Hi,
Did you check whether you have warning lines with libraries not found message ?
Note that you
greaterThan(QT_MAJOR_VERSION, 4):
lines don't make sense. This construct is only useful for the widgets module. -
@remizero It sounds like it isn't linking the libs you need. So since you are moving from static to dynamic libraries I'm guessing your project settings are wrong.
I can grab the project and compile it and I'll let you know in a bit.
-
@remizero Ok I found your problem..
The blocks with
win32:CONFIG
andelse:unix:
etc are not correct.I don't remember the exact syntax since I don't work with qmake much any more (prefer cmake) so I'll let you google it or someone else can come in and tell you how.
But basically I noticed when I built it that the compile line that was failing looked like this:
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Qt/lib -o ../mainecomoditorgui main.o MainWindowGui.o moc_MainWindowGui.o -L/usr/local/Qt/lib -lQt5Widgets -lQt5Gui -lQt5Xml -lQt5XmlPatterns -L/opt/Qt/5.8/gcc_64/lib -lQt5Network -lQt5Core -lGL -lpthread
You'll notice there is no
-L../../com/ecosoftware/window
and no-lmainwindow
. So since you never included that library path or linked to the mainwindow lib that is why things are undefined.To confirm I added this to your
examples/maingui/maingui.pro
file:LIBS += -L../../com/ecosoftware/window -lmainwindow
And when I built it worked. Not completely as there was another project file with the same errors but I confirmed the problem, so now that you know why you should be able to fix it easily. ;)
-
Thanks for your prompt response.
Hi @SGaist, that line automatically places the QtCreator, so I only leave it there because it allows me to add the additional Qt modules that I require, when I require clear is jejeje.
Hi @ambershark. Well, taking into account what you told me, has made a more exhaustive review of my files.
LIBS + = -L../../com/ecosoftware/window -lmainwindow
I still had a question about why? It did not work correctly if indeed that line that your comments are included in the LIBS variable for all platforms.
Well, I realized that by doing tests on tests, I was not looking for the backslash at the end of the last included library.
The funniest thing about everything is for the code published in the post, if it worked, then the correct thing, but in the code that is in the attachment, I left it as it was in the tests and that's where it can be appreciated The error
For example, attachment with the error:
Win32: CONFIG (release, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \ Else: win32: CONFIG (debug, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \ Else: unix: LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/ -app \ -L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow \ INCLUDEPATH + = \ ../../ui \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow DEPENDPATH + = \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow
Correct form of the file, correcting the error:
Win32: CONFIG (release, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow Else: win32: CONFIG (debug, debug | release): LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \ -L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow Else: unix: LIBS + = \ -L$$OUT_PWD/../../com/ecosoftware/ -app \ -L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow INCLUDEPATH + = \ ../../ui \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow DEPENDPATH + = \ $$PWD/../../com/ecosoftware/app \ $$PWD/../../com/ecosoftware/window/mainwindow
Thank you very much for your help, I hereby solve this thread. I hope this explanation will help others identify the why? Of this error when they only work with qmake.
-
Just use
QT += module
That test is really only useful for code bases that should be built with both Qt 4 and Qt 5 since the widgets have moved to their own module in Qt 5.