TEMPLATE = lib ?
-
Duplicate post
I am still looking for an answer...
My Qt example "terminal" runs fine when TEMPLATE = app.
When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".I have checked all my headers etc many times and there are NO compiler errors.
It is definitely a linker error and I cannot find it.Here is my CURRENT question:
the "terminal " project contains THREE header files ,
do I have to add ALL of them to the class where the "terminal" library is used ?I did , and I still get same "undefined reference" , BUT only on the main class - the other classes do not generate any errors - compiler or linker.
BUT at this point I need the main class / object to link.The others SHOULD work since it runs just fine as TEMPLATE= app.
PS
The "terminal" runs main (parent) and "pop up" dialogs, I did try to delete the dialogs but it did not go well - too many dependencies.. -
@AnneRanch
I did explain in your other post that this has nothing to do with header files or compilation.If you showed the full link command line for each of the two cases (
app
/lib
) we ought be able to spot where one of the two fails to link with the necessary.o
file which generates the "undefined reference". -
@AnneRanch
Probably the final one each time you have to build. They will both start withld
(or/bin/ld
or whatever) I think, though it might begcc
/g++
/clang++
as a wrapper. The line will contain somefilename.o
files, and it won't have any.cpp
s. In theapp
case it will be building your executable, in thelib
case it will be building some*.so
file, the library.We should find that the one which gives an error does not contain your, I forget exactly what, but some
...BLUETOOTH...terminal.o
file, while the one which works does contain that. Or, one of them has yourmain.o
while the other does not. One of those combinations should be why you get the "undefined reference" from the linker.Hang on, I'm looking at your post https://forum.qt.io/topic/155810/undefined-reference-again-discussion/8
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
OK, that is your
-o libterminal.so.1.0.0
, for the library, thelib
case, and that works. It has bothmainwindow.o
andterminal_ORIGINAL_mainwindow.o
, that is good.Now we need to see the equivalent link line when you build for
app
and you get the "Undefined error" message from the linker. I think it will havemainwindow.o
but notterminal_ORIGINAL_mainwindow.o
, and that is bad.Hmm, I see you say
My Qt example "terminal" runs fine when TEMPLATE = app.
When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".
But I think that other thread shows tour
lib
case works? I'm lost now :) -
@JonB I have TWO modified "terminal " projects - they both work as TEMPLATE = app.
To make sure , I run them as stand-alone projects, not as part of the "subdirs".The less modified original "terminal" does not work as TEMPLATE=lib.
Can you comment on the question about including ALL headers ?
-
@AnneRanch said in TEMPLATE = lib ?:
The less modified original "terminal" does not work as TEMPLATE=lib.
Then if you wanted help with that it is the one whose
ld/g++/clang++ -o something.so
link line generates an "Undefined reference to ..." error.I can only say that if you get an "Undefined reference" error from the linker, which is what I understand you to be asking about:
When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".
It is definitely a linker error and I cannot find it.that is not to do with you including or not including
.h
files in.cpp
files. It is to do with your code actually calling a function in another.o
file and that not being passed to the linker to resolve. -
@JonB said in TEMPLATE = lib ?:
that is not to do with you including or not including .h files in .cpp files.
That has been discussed and concluded TRUE.
Let's move on...It is to do with your code actually calling a function in another .o file and that not being passed to the linker to resolve.
That is NOT the case - I have described how I use "add library"
to add it to subproject .pro file - who is using it.Let's move on...
I suspect the link to .so IS THE issue...