我正在修改大量遗留 C++ 代码,这些代码对旧的 commoncpp 库有一些依赖。我们想用更现代的东西(例如 Boost)替换 commoncpp。
首先我需要找到所有使用commoncpp提供的函数和方法的地方。显而易见的蛮力方法需要太多时间(特别是对于像我这样认为计算机应该完成繁琐工作的“懒惰”程序员:-)。
我正在寻找有关如何加快该过程的想法。
如果 ld
有一个标志,上面写着“继续寻找外部引用并吐出任何丢失的引用”,这可能会完成所需的一切。
我们的代码分布在许多目录中,具有分层递归 Makefile,如果这对建议的解决方案有所不同的话。
环境是带有 Gnu 编译器链的 FreeBSD。
我也用 C 标记了它,因为大多数可以为 C 解决此类问题的解决方案也应该为 C++ 解决它。
(猜你不能格式化评论)
在我的构建中使用 --cxref
,然后使用此管道:
% egrep 'ccgnu2|ccext2' output.txt | sort | uniq
给我这个:
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
我想知道我是否可以使用上述内容来获得我需要的东西。
最佳答案
来自 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.
您需要做的就是在不链接实际库的情况下进行编译。
在我的机器上:
~/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'
.
.
.
关于gcc - C++ 查找并删除对很少使用的库的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16676390/