S
S
sitev_ru2017-06-14 17:55:11
linux
sitev_ru, 2017-06-14 17:55:11

What's the problem with including nested libraries?

I create in Qt Creator, but I think that the problem is not in it ...
I create a static library lib1 in Qt without using QtCore. The project is obtained, by default, containing the files lib1.cpp and lib1.h,
which describe the empty class Lib1 (only an empty constructor).
I create a test application "Project without Qt", which is called test, I connect this lib to it - everything works.
Now I create the static library lib2 as well as lib1.
lib2.cpp:

#include "lib1.h"
#include "lib2.h"

Lib2::Lib2() {
  Lib1 *lib1 = new Lib1();
}

I compile the Lib2 library - so far everything works as it should.
I insert the line into my application: And then a strange error appears:
Lib2 *lib2 = new Lib2();
Undefined reference to Lib1::Lib1() in lib2.cpp

What's with the weird error? What am I doing wrong? Perhaps because of Linux?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2017-06-14
@sitev_ru

The order in which libraries are linked is important. If you first link with lib1 and then with lib2, and there are no links to lib1 in test, then what you see will be. It is necessary either to order the libraries so that first those that access external functions go first, and then those that define these functions. Or put all interdependent libraries inside a pair of --start-group --end-group or -( -) directives.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question