Search code examples
mingw-w64

Find missing symbols in mingw library


Given ar libraries and possibly object files, what is the best way to find all of the unresolved external symbols? One possibility is to run the linker and then capture the errors, but sometimes it stops after a certain number of symbols. Is there a better way?


Solution

  • In your mingw-w64 installation's bin directory, along with the C and C++ compilers, linker and make tool, you should other programs that make up the GNU binutils.

    Several of these (nm, objdump, readelf) can parse the symbol tables of object files or shared or static libraries. The simplest to use is probably nm. Assuming that the bin directory is in your PATH, open a command prompt in the directory containing the libraries or object files your are interested in and run:

    nm -u libfoo.a
    

    or:

    nm -u foo.obj
    

    to list the undefined symbols in libfoo.a or in foo.obj.

    If these files contain C++ symbols that you want to see demangled then add -C to the nm options.

    These tools all recognize that a static library libfoo.a is just an archive of object files so nm ... libfoo.a gives you just the same results as if libfoo.a was replaced with a list of the object files within it.