Skip to content
Advertisement

Method is both defined and undefined in a static Linux library

I’m using visual studio 2019 and compiling for ARM android. One of the twelve libraries in my solution is failing to link properly.

It is showing a sizable number of class methods that are both defined and undefined.

Here is one example using the command line:
nm -C -g Services_Droid.a 1>Services_Droid_All.txt

I get a listing and the example constructor method shows::

E:codeServices_Droid_All.txt (5 hits)

Line 834:           U hCitem::hCitem(int)
Line 1073:          U hCitem::hCitem(int)
Line 1197: 0000006c T hCitem::hCitem(int)   // there is only one definition in this file
Line 1199: 0000006c T hCitem::hCitem(int)
Line 5747:          U hCitem::hCitem(int)

Linking this library into my main program generates a duplicate of the three undefined items which fails the link.

There are a large number of methods that have the same issue in this library.

Any ideas for what causes this and how to fix it would be greatly appreciated.

Advertisement

Answer

It is showing a sizable number of class methods that are both defined and undefined.

That is completely normal: an archive library is not much more than a collection of .o files. One of these files defines hCitem::hCitem(int). A few other files reference it.

You can observe that this is in fact the case by using nm -AC Services_Droid.a.

One of the twelve libraries in my solution is failing to link properly.

You should ask a separate question, explaining your actual problem.

Advertisement