Undefined reference errors in Windows, working fine in Linux
-
wrote on 10 Feb 2020, 18:53 last edited by
Hi there,
Sorry if this question is too elementary but I am not highly experienced in C++ and I can't find by myself what's going wrong with this issue.
I have been reading the book "Learn QT 5", by Nicholas Sherriff, and so far I have been doing well and I can recommend it as a nice one to get started in all things Qt and C++, in my own opinion.
I have been doing everything in Ubuntu Linux 18.04, with g++ 7.4.0 and Qt 5.13.0. As I said, just following the book I never had a single problem, everything always compiled and ran just fine. However, I cloned my Git repo into a Windows 10 system, with g++ 9.2.0 and Qt 5.14.0 and the exact same code does not compile any more, giving me "undefined reference" errors to a bunch of methods of a base class several other classes inherits from.
The base class bringing those "undefined reference" errors is
Entity
. So I am having a large amount of errors when I try to subclass or get an instance from it, like for example when I try to buildcm-ui
I get this error (amongst others):address.h 13:
undefined reference to cm::data::Entity::~Entity()
...which I find weird, because the method is indeed implemented and also I can build
cm-lib
with no issues at all.I would like to remark again: the same code in that repo works perfectly in Ubuntu setup. So I am wondering: is there any critical difference between Windows and Linux I am missing here that makes the project code/setup error in Win?
Thanks.
-
Hi and welcome to devnet,
Unless you are building your library statically, you have to export the symbol you want to use from your library.
See here for more details and how to do it using Qt.
-
You need to mark the functions/classes you want to use outside the library as visible: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
-
Hi and welcome to devnet,
Unless you are building your library statically, you have to export the symbol you want to use from your library.
See here for more details and how to do it using Qt.
wrote on 10 Feb 2020, 19:38 last edited by Jose L. Patino 2 Oct 2020, 19:40@SGaist Oh, thank you very much. I see now what my problem was: I forgot to define the
CMLIBSHARED_EXPORT
symbol in theEntity
class.Once I did it now everything builds flawlessly. So I fixed the
Entity
class declarationclass Entity : public QObject { ...
by adding
CMLIBSHARED_EXPORT
:class CMLIBSHARED_EXPORT Entity : public QObject { ...
Thank you again, that was really a killer response :) And thank you @Christian-Ehrlicher too!
1/4