0

I'm starting to get "undefined reference" linker errors with an NDK project. I understand what these typically are - ie - a method missing from a .cpp file which is declared in a .h file.

I have a main shared library that links in 2 static libraries 'libTTComponents.a' and 'libTTDialogs.a'. Static library 'libTTDialogs.a' uses C++ classes defined in 'libTTComponents.a'. This has been working until I made changes recently. Unfortunately the project is a cross-platform project and I have made a number of changes under Windows since I last worked on Android and incrementally going through all of the changes is going to be very time consuming.

Is there a linker/compiler switch I can enable when building my static libraries that will produce a list file containing all of the external references?

I would like to be able to cross reference what is actually in the static libraries against a map file when I try to link the static libraries against the main shared library. That would allow me to determine why the linker believes certain references are missing.

My Android.mk files for both the static libraries and my main module haven't changed so I am at a complete loss right now.

UPDATE: I have found that 'nm' can be used to view the symbols in a .a file:

nm libTTComponents.a

This shows me the following line (among others):

00000000 T _ZN11CSampleEdit4DrawEv

I have a file SampleEdit.cpp which contains methods for my CSampleEdit class. In particular I'm focusing on the CSampleEdit::Draw() method which the linker cannot find:

[armeabi-v7a] SharedLibrary  : libmain.so
/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /work/TT/android-TT/jniLibs/armeabi-v7a/libTTDialogs.a(BaseDialog.o): in function CBaseDialog::DrawSampleEdits():/work/TTracker/BaseDialog.cpp:730: error: undefined reference to 'CSampleEdit::Draw()'

Now that I know that I can see what symbols are within a static library .a file, is there a way to determine what other static libraries or modules are trying to access? The error above shows that my other library libTTDialogs.a is unable to find CSampleEdit::Draw() which is inside the libTTComponents.a library.

I have also discovered:

ar x libTTComponents.a

This gives me a load of errors such as:

SampleEdit.o/: No such file or directory

My .a files are in a different location to the .o files.. I don't know if this is why 'ar' is giving me these errors or if the .o files need to be in the same folder as the libTTComponents.a. I would have thought that libTTComponents.a on its own (plus my .h file) would be enough for another library to be compiled and linked against it.

Interestingly enough, if I add all of the libTTComponents.a source files into the main module's Android.mk, it links without error.

I am starting to suspect that different symbols are created for the libTTComponents classes when libTTDialogs is built compared to those created when libTTComponents itself is built.

SparkyNZ
  • 6,266
  • 7
  • 39
  • 80
  • Only guessing here, but it might be due to the link order of your libraries? The linker handles libraries in the order they appear on the command line, so if libfoo.a depends on libbar.a but you have `-lfoo -lbar`, it won't be able to find the symbols from libbar.a. – Dan Albert Oct 19 '16 at 08:39
  • @DanAlbert thanks - I can give that a try. I suspect it relates to one library using the class of the other library and vice-versa. I have a working copy at revision 750 and a broken revision 1008.. somewhere between lies the evidence. Shame I didn't have an automated build to ensure my Android/iOS version continue to build. :) – SparkyNZ Oct 20 '16 at 03:00

0 Answers0