CXJ
CXJ

Reputation: 4469

C++ Find and remove references to little-used library

I'm modifying a large collection of legacy C++ code which has a few dependencies on the old commoncpp library. We want to replace commoncpp with something more modern (e.g. Boost).

First I need to find all the places commoncpp-provided functions and methods are used. The obvious brute force methods take too much time (especially for "lazy" programmers like me who believe computers should do the tedious work :-).

I'm looking for ideas on how to speed up the process.

If ld had a flag that said "continue looking for external references and spit out any missing references" that might do the everything needed.

Our code is spread over many directories, with hierarchal, recursive Makefiles, if that makes a difference to a proposed solution.

Environment is FreeBSD with Gnu compiler chain.

I tagged this with C as well, since most solutions which would solve this kind of problem for C should solve it for C++ also.

(guess you can't format comments)

Using --cxref in my build, and then this pipeline:

% egrep 'ccgnu2|ccext2' output.txt | sort | uniq

Gets me this:

on-virtual thunk to ost::ttystream::~ttystream() ../../lib/libccext2.so
non-virtual thunk to ost::unixstream::~unixstream() ../../lib/libccext2.so
ost::CRC16Digest::getSize() ../../lib/libccext2.so
ost::CRC16Digest::initDigest() ../../lib/libccext2.so
ost::CRC16Digest::~CRC16Digest() ../../lib/libccext2.so
ost::CRC32Digest::getSize() ../../lib/libccext2.so

I wonder if I can so something useful with the above to get what I need.

Upvotes: 3

Views: 285

Answers (1)

Elazar
Elazar

Reputation: 21645

From the ld man page :

--warn-unresolved-symbols

If the linker is going to report an unresolved symbol (see the option --unresolved-symbols) it will normally generate an error. This option makes it generate a warning instead.

All you need to do is compile without linking the actual library.

On my machine:

~/workspace/jos$ make 2>&1 | grep reference
lib/spawn.c:129: warning: undefined reference to `copy_shared_pages'
user/primes.c:25: warning: undefined reference to `fork'
.
.
.

Upvotes: 2

Related Questions