PDA

View Full Version : error: undefined reference to. Where?



remizero
22nd March 2017, 04:32
Hello again, friends.

In this opportunity I am writing to see how far they can guide me with this problem that has been presented to me.

After a question I asked a few weeks ago and orientations of anda_skoa, I have managed to "compile" a project that I have been developing gradually. The point is that when compiling my executable I have the following errors:



/home/remizero/Projects/Qt/ecomoditor-Debug/common/language/libphp.so:-1: error: undefined reference to `With: Ecosoftware :: Ecomoditor :: Common :: Language :: Core :: Model: : ClassAbs :: staticMetaObject '
/home/remizero/Projects/Qt/ecomoditor-Debug/common/addons/libclass-viewer.so:-1: error: undefined reference to `With: Ecosoftware :: Ecomoditor :: Common :: Language :: Core :: Model :: MethodAbs :: getMethodReturn () const '
/home/remizero/Projects/Qt/ecomoditor-Debug/common/libactions.so:-1: error: undefined reference to `With: Ecosoftware :: Ecomoditor :: Common :: CodeGenerator :: Core :: ClassGeneratorAbs :: save (QString) '


Well they really are more, but I think with them is enough to get an idea of ​​what happens to me. Clarifying that all libraries get to compile completely and without problems, I only throw the undefined reference error when I try to compile the executable that is:


Ecomoditor/bin/ecomoditor

It should be noted that I have reviewed a lot of documentation and references on the web about this problem, but so far I have not been able to solve it with any solution offered, which in most cases have nothing to do with mine.

I'm working on Debian 9 64bit, QtCreator 4.2.0, Qt 5.7.1

In addition to this, I can comment that all the libraries work correctly, I have tried them all separately and all the code works correctly, costing me a lot to separate this project in libraries because initially I had it as a whole in an app type project.

You may notice some hazards in the .pro files, but it's only so far that I'm programming something serious with Qt and of course there are the errors that are being presented to me. I put what I take so far from the project to have it tested and verify where the error may be and then they can tell me that I am doing wrong and where to go.

By the way, what is commented in .pro files is because I'm not using it yet and so I did not put those portions of code.

No more to add, thank you very much in advance.

d_stranz
22nd March 2017, 19:59
Undefined references are always due to failure to link to a library or object code module that contains the implementation of those classes or methods. I don't know about Debian, but on Windows you cannot link a debug mode program to release mode libraries or vice-versa. This could be another cause of undefined references.

Check your linker options to make sure you have included all of the necessary libraries or object files. If the undefined classes are QObject-based, make sure that MOC has been run to generate the moc*.cpp files and that these are also being compiled. Sometimes a qmake / make clean is needed.

remizero
22nd March 2017, 23:47
Hi d_stranz, thanks for your quick reply.

I understand what you say, although at the configuration level of the .pro file I have no reference to the compilation mode, the QtCreator configuration I have at the moment for compilations in debug mode, so I do not think it is that aspect, but I'll give you a look at the QtCreator configuration again to see if any unexpected and/or unintentional changes have been made without my noticing.

On the other hand what you comment about the preprocessor MOC, yes. The moc_.cpp files are being generated with their respective moc_.o.

I also cleaned the project (including deleting the whole folder), running qmake, then build (including, one by one each sub project), and finally run, but at the time of build the executable project that in this case is ecomoditor/Bin/ecomoditor, throws the above mentioned errors to me.

I will continue to look in the documentation, which I may be doing wrong so that it does not compile properly.

remizero
28th March 2017, 04:16
Hello friends, I am writing to give for solving the problem raised.

The detail was, he wanted to run without learning to crawl first.

Although the problem was not in the libraries proper, since each one does what it has to do, there was a detail in the order in which the libraries were generated.

I had to add one by one the libraries to be able to realize the order that had to be compiled and linked and thus to prevent the mistakes of linking, because that was my whole problem.

Thanks for your help.

remizero
8th April 2017, 18:06
Hi again. Reactivate this post, to clarify the error due to lack of reference in link time that was coming to me.

Having written the "solution" to this problem and doing a serious test on tests, I was again presented with the problem.

The detail was at the moment of commenting on the lines of libraries that I did not want to use for various functional tests and for decoupling all the code.

Well, at the moment of commenting on these lines of libraries in the .pro file, I forgot to remove the backslash, leaving in many cases configurations like this:


win32:CONFIG(release, debug|release): LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/singleinstance/debug/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/xmlmanager/debug/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -ltabpanel \
#-L$$OUT_PWD/../../common/debug/ -lworkspace \
else:win32:CONFIG(debug, debug|release): LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/singleinstance/debug/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/xmlmanager/debug/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -ltabpanel \
#-L$$OUT_PWD/../../common/debug/ -lworkspace \
else:unix: LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -ltabpanel \
#-L$$OUT_PWD/../../common/ -lworkspace \

Where, the correct form would be the following:


win32:CONFIG(release, debug|release): LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/singleinstance/debug/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/xmlmanager/debug/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -ltabpanel \
#-L$$OUT_PWD/../../common/debug/ -lworkspace \
else:win32:CONFIG(debug, debug|release): LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/app/debug/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/singleinstance/debug/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/xmlmanager/debug/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/debug/ -lmainwindow
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/debug/ -ltabpanel \
#-L$$OUT_PWD/../../common/debug/ -lworkspace \
else:unix: LIBS += \
-L$$OUT_PWD/../../com/ecosoftware/ -lapp \
#-L$$OUT_PWD/../../com/ecosoftware/ -lsingleinstance \
#-L$$OUT_PWD/../../com/ecosoftware/files/ -lxmlmanager \
-L$$OUT_PWD/../../com/ecosoftware/window/ -lmainwindow
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -lexpandtoolbar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -lmenubar \
#-L$$OUT_PWD/../../com/ecosoftware/window/components/ -ltabpanel \
#-L$$OUT_PWD/../../common/ -lworkspace \

Thanks also for the help lent me, he guided me a lot to understand the why? Of this error.