Undefined reference - again - discussion
-
MORE ADDENDUM
Is this red / green line thru #67 - #74 an error indicator ?
For sake of discussion - I will make an exception and ask for reference to Qt document (RTFM)....
ADDENDUM
Is this just a confirmation of the issue and not really more help info ?
There is only ONE MainWindow in the project and it really does not point to source of the problem, but to the "result" object file.
Am I correct ?
I have deleted all optional sources from the .pro file, same issue.
make[1]: Leaving directory '/mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/terminal_Bluetooth'
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23
mainwindow.o: in functionMainWindow::MainWindow()': mainwindow.cpp:(.text+0x1c8): undefined reference to
terminal_ORIGINAL_MainWindow::terminal_ORIGINAL_MainWindow(QWidget*)'
/usr/bin/ld: mainwindow.cpp:(.text+0x1e7): undefined reference to `terminal_ORIGINAL_MainWindow::terminal_ORIGINAL_MainWindow(QWidget*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: Leaving directory '/mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/mdi'
make[1]: *** [Makefile:293: mdi] Error 1
make: *** [Makefile:595: sub----A_BT_LIBRARY-mdi-make_first] Error 2
10:13:15: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project A_Mar7_MAR17 (kit: Qt 5.15.2 (gcc_64))
When executing step "Make"Undefined reference - again - discussion
help me to improve debugging process.I am posting this to get some MORE ideas how to find the code problem.
Currently I have the class in question added to my "parent class" header :
public:
terminal_ORIGINAL_MainWindow *pTOMW;:there is no indication of error there
I have added this code to my parent constructor :
terminal_ORIGINAL_MainWindow *p = new terminal_ORIGINAL_MainWindow(); p->show(); pTOMW = new terminal_ORIGINAL_MainWindow(); pTOMW->show();
There is no indication of error there.
The class in question runs just as expected when
I change the TEMPLATE in .pro to app, BUT fails when the TEMPLATE is set to library.The compiler builds the library and the there ARE NO missing headers.
The intelisense has NO ISSUES suggesting the code options when editing - hence there is a valid reference for intelisense to work as expected.
Yes, the correct library was added to parent class.
Yes, I have similary modified class / project added to my subprojects and it works as expected.
Hence i HAVE , OBVIOUSLY, missed something when duplicating SAME Qt example. ( No need to confirm that...)In an essence - the code works as an independent project, but fails to work when added to subdir project.
I am asking for help trying some other ways to identify the missing code.
I was ho[ping I try to find some way to compare the working code with the failing one, perhaps file by file...
I am NOT asking for RTFM or actual code , I am asking for help to improve debugging process.
/mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/mdi/mainwindow.cpp:-1: error: undefined reference to `terminal_ORIGINAL_MainWindow::terminal_ORIGINAL_MainWindow(QWidget*)'
PS
Need more info ? ASK -
@AnneRanch
It is a linker error. You just tell that by looking at the error message, e.g./usr/bin/ld: mainwindow.cpp:(.text+0x1e7): undefined reference to `terminal_ORIGINAL_MainWindow::terminal_ORIGINAL_MainWindow(QWidget*)'
ld
is linker. Compilations/headers/includes are not relevant.You have some
.cpp
file which defines the classterminal_ORIGINAL_MainWindow
. That gets compiled to a.o
, perhapsterminal_ORIGINAL_MainWindow.o
.Linking with
mainwindow.o
needs this because somewhere inmainwindow.cpp
you create aterminal_ORIGINAL_MainWindow
instance.-
When the link is unsuccessful, you are linking with
mainwindow.o
but missingterminal_ORIGINAL_MainWindow.o
, so it fails. -
When the link is successful, either you are not linking with
mainwindow.o
or you are and you link withterminal_ORIGINAL_MainWindow.o
too, so it succeeds.
Perhaps what you link with differs between your "app" and "library" templates?
-
-
@JonB OK, if it is linker error
than I won't see any reference to source , correct?If that is true, now for next question
what am I looking for as far as linker problem ?
I generally do not write specific linker options - for obvious reason - the default linker options generally work...
( If it is not broke why fixing it ...)I just went thru building test subproject ( library) and have no issues , complier or linker.
From that point of view -just my liker options are fine...
My subproject contains several libraries with NO LINKER ISSUES.Perhaps linking / adding the problem library is the issue.
( you eluded to that )
Than I need to go back to .pro and REMOVE the suspect library. That may give SAME error , or maybe "missing library " error ?Anyway, that is exactly the help I was asking for and I do appreciate that,
-
@AnneRanch progress (?) report
I have removed the offending project for .pro SOURCE
Result is NO error at all - expected BUT
I had to run "clear and rebuild " to get there. Odd.Commenting out the test project library resulted in "undefined reference " to it - somewhat expected.
BUT
I cannot duplicate SAME error by rerunning "clear and rebuild " - the error is gone...
and BUT
there were no "linker / object file errors as with the troublesome project.My conclusion , so far , to have consistent (error) results
- it is better to "clear and rebuild" SEVERAL TIMES ...
-
@AnneRanch said in Undefined reference - again - discussion:
Is this red / green line thru #67 - #74 an error indicator ?
The red line is unsaved changes and the green line is saved changes. This helps you to find the parts in the file that you have changes since opening it.
@AnneRanch said in Undefined reference - again - discussion:
what am I looking for as far as linker problem ?
I generally do not write specific linker optionsIn the context of Qt everything would just be handled through the project file. If you add a .cpp file to the project the corresponding .o file should automatically be added to the linker flags.
@AnneRanch said in Undefined reference - again - discussion:
I had to run "clear and rebuild " to get there.
I used the word "should" above. No build system is perfect and occasionally you need to clear everything and do a rebuild. In extreme cases, with qmake you need to "clear", then explicitly "run qmake", and only then rebuild your project.
-
@AnneRanch said in Undefined reference - again - discussion:
I change the TEMPLATE in .pro to app, BUT fails when the TEMPLATE is set to library.
this might be the crux of the problem, did you do that previously to the error appearing as well ?
The build system usually doesn't rebuild object files on its own, if there are no changes in the source files. But changing from standalone app to library does require different object files.
this is for example one of the reasons, why shadow build folders in QtCreator have the QtVersion/Compiler in its name. To not mix obj files created.
-
@J-Hilk I am using changing the TEMPLATE as debugging tool.
In my case just to make sure the code works / runs independent of library usage.
I actually have two copies of the "problem
" source code - one in subdirs project and one as an independent project.Mainly because when I change the template to app , I cannot "run" the problem code , the main subdirs project does not like "two" main apps.
BTW
I think the problem is in "mixing " include and actual link to the .so code - I am going to verify all of the next.
-
@AnneRanch OK, here is complier / linker output AFTER the TEMPLATE = lib
09:31:01: Running steps for project terminal...
09:31:01: Starting: "/home/nov25-1/Qt/5.15.2/gcc_64/bin/qmake" /mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/CCC_SOURCE/TERMINAL_example_source/terminal/terminal.pro -spec linux-clang CONFIG+=debug CONFIG+=qml_debug
Project MESSAGE: RESTOREd ALL resouces - DEBUG commneted out options resouces - same issue
Project MESSAGE: Changed back to TEMPLATE = lib
/mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/CCC_SOURCE/TERMINAL_example_source/terminal/terminal.pro:36: message(message) requires one argument.
Project MESSAGE:
09:31:01: The process "/home/nov25-1/Qt/5.15.2/gcc_64/bin/qmake" exited normally.09:31:01: Starting: "/usr/bin/make" -f /mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/CCC_SOURCE/TERMINAL_example_source/terminal/Makefile qmake_all
make: Nothing to be done for 'qmake_all'.
09:31:01: The process "/usr/bin/make" exited normally.09:31:01: Starting: "/usr/bin/make" -j4
rm -f libterminal.so.1.0.0 libterminal.so libterminal.so.1 libterminal.so.1.0
clang++ -ccc-gcc-name g++ -Wl,-rpath,/home/nov25-1/Qt/5.15.2/gcc_64/lib -shared -Wl,-soname,libterminal.so.1 -o libterminal.so.1.0.0 main.o settingsdialog.o console.o terminal_ORIGINAL_mainwindow.o qrc_terminal.o moc_settingsdialog.o moc_console.o moc_terminal_ORIGINAL_mainwindow.o /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so/home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5SerialPort.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lGL -lpthread
ln -s libterminal.so.1.0.0 libterminal.so
ln -s libterminal.so.1.0.0 libterminal.so.1
ln -s libterminal.so.1.0.0 libterminal.so.1.0
09:31:03: The process "/usr/bin/make" exited normally.
09:31:03: Elapsed time: 00:02.1.Does THIS output help me to ADD correct #include header to the "parent " class ?
2.Does THIS output help me to ADD correct "library" to the "parent " class ?
Using "Add library" option - internal or external or ...
-
@AnneRanch
After
changing the #include to#include < header file >
adding library using "external " with full path
I still get same , agree this is a linker, error pointing to here:
// TEST_SUBPROJECT text = " TEMPORARY WINDOW TITLE CHANGED index 40 ..."; TEST_PROJECT_MainWindow *pTEST_INDEX = new TEST_PROJECT_MainWindow(); pTEST_INDEX->setWindowTitle(text); add_mdi_subwindow (pTEST_INDEX); // debug terminal issue This code fails but there is no compiler error indicated **terminal_ORIGINAL_MainWindow *pTERMINAL = new terminal_ORIGINAL_MainWindow(); add_mdi_subwindow (pTERMINAL);** This code fails but there is no compiler indicated
-
@AnneRanch said in Undefined reference - again - discussion:
This code fails but there is no compiler error indicated
That is because it is a linker error. You told the compiler that there is a
terminal_ORIGINAL_MainWindow
class in another file, but you did not link withterminal_ORIGINAL_MainWindow.o
, which you need to do as it has the class code, so the linker could not succeed.If you had not
#include
d theterminal_ORIGINAL_MainWindow.h
file THAT would have given a compilation error on thenew terminal_ORIGINAL_MainWindow()
line. But including that allows it to compile, and says theterminal_ORIGINAL_MainWindow.o
object file will be provided at link time. But, for whatever reason, it is not when you get your error.That is what the
Undefined reference
error message from linker (ld
) indicates each time. -
This post is deleted!
-
UPDATE
I have given up trying to physically find the "linker" problem.
I am trying a DIFFERENT way to resolve this AND could use some help.I now have TWO "subdirs" projects - my main one , the one which refuses to work , and working "helper project".
The "helper project" works as expected - here is the result:
![2c014c03-91ca-4ba5-ae24-cf8f36e7d9c3-image.png](https://ddgobkiprc33d.cloudfront.net/e8891de0-f237-4934-894d-ed0fc54abae2.png
As "subdirs" , the "helper project" has main .pro and terminal .pro.
I repeat - the "terminal" helper project works BY ITSELF as expected.
I have successfully added the "helper project " to my main project. - "TEST_MAIN_SUBPROJECT "
Here is the picture of ALL .pro files in it:
HERE IS WHAT I NEED HELP WITH
Currently the TEST_MAIN_SUBPROJECT runs
TERMINAL_SUBDIRS_PROJECT "MAIN_PROJECT" - as posted at the start of this post.I need to SWITCH it to run
A_Mar7_MAR17.pro
the original , faulty project , which refuses to link with "terminal".
I am hoping that I can then use the working
TERMINAL_SUBDIRS_PROJECT and its working "terminal".
My main, so far faulty , project MaiN WINDOW IS "mdi.pro".
I would prefer to use "mdi.pro"
, but if it will work I could run theTERMINAL_SUBDIRS_PROJECT "MAIN_PROJECT"(,pro) main window" with
A_Mar7_MAR17.pro as child.I do realize this approach is convoluted, but my main goal is is to link "TEST_MAIN_SUBPROJECT " with "terminal" irregardless how many parent - child levels it takes.
THANKS
-
@AnneRanch UPDATE
Question
what configures the Qt to run TEST_MAIN_SUBPROJECTpro ?09:12:11: Running steps for project TEST_MAIN_SUBPROJECT...
09:12:11: Starting: "/home/nov25-1/Qt/5.15.2/gcc_64/bin/qmake" /mnt/A_BT_DEC10/BT__PROGRAMS/A_APR/A_APR6_MAR7_MAR19_CLEAN/A_BT_LIBRARY/CCC_SOURCE/TEST_MAIN_SUBPROJECT_PROJECT/TEST_MAIN_SUBPROJECT/TEST_MAIN_SUBPROJECT.pro -spec linux-clang CONFIG+=debug CONFIG+=qml_debug CONFIG+=force_debug_info CONFIG+=separate_debug_info
Project MESSAGE:
Project MESSAGE: run TEST_MAIN_SUBPROJECT.pro
Project MESSAGE:it is LAST .pro in the project
-
@AnneRanch said in Undefined reference - again - discussion:
what configures the Qt to run TEST_MAIN_SUBPROJECTpro ?
when your project creates multiple executables that could potentially be executed. You can specify inside the project tab under "run settings" which executable is supposed to be run.
-
@JonB Unfortunately 'run setting" does not let select .pro but sudirs project executable.
That does not help to bypass the terminal problem.
If I select modify and select "mdi" it actually runs the "mdi" BEFORE the modification.
The editor shows errors , it should, and it should not run. -
-
@JonB OK, back to terminology...
I use "Add library" to add it to the subproject / object who needs it...
I let Qt to select "internal" library ....by project name - AKA "terminal"
From there it is Qt who actually adds stuff - mostly to .pro file.I have to add required headers...
editor and compiler passes the headers as validThen I usually run "Clear" and "Rebuild".
That is it...I do not see the references to library.o AND library.so until the complier / linker is done.
The linker error is actually very last few lies of the "Rebuild" process.