amdube
amdube

Reputation:

circularly linked static libraries (linux )undefined libraries

I did a build for static libraries and put then at a location. Now when i build my source i get UNDEFINED REFERENCES for inter library calls. For example:

/home/xyz/lib/libA.a(ClassA.a):undefined reference to classB::funB()

here classB.a is also a static library .

In my source's project file the static linking order is :

LIBS+=   -lclassB -lclassA

Now when i reverse the libraries order i start getting error in classes of library B for function calls inside library A.

Upvotes: 1

Views: 602

Answers (2)

amdube
amdube

Reputation: 73

Ok friends I have found the solution .

I was using qmake build tool on gcc , i just needeed to tell qmake that some of my static libraries are circularly dependent .

So i modified my .pro file with a qmake linker flag

   QMAKE_LFLAGS += -Wl , --start-group --end-group

gcc's documentation says that you need to put your archive names between --start-group --end-group , but qmake is smart enough to find out the dependent libs , and will do that automatically .

Have Fun .

Upvotes: 0

Paul R
Paul R

Reputation: 213080

For this kind of situation you generally need e.g.

LIBS += -lclassA -lclassB -lclassA

Linking the classA library twice helps to resolve the circular dependencies.

Upvotes: 2

Related Questions