【问题标题】:how do i use find, nm, and grep to find a symbol among many shared libraries?如何使用 find、nm 和 grep 在许多共享库中查找符号?
【发布时间】:2015-04-20 22:31:16
【问题描述】:

我正在努力使用正确的命令来执行以下操作:

查找所有包含某个符号的共享库 (*.so)。

这是我尝试过的:

find -iname '*.so*' -exec nm {} \; | grep -H _ZN6QDebugD1Ev

上面给出了一些找到符号的输出,但没有查明符号出现的文件名。我给 grep 告诉它打印文件名的任何标志都丢失了,因为 grep 是从标准输入提供的。

(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):0015e928 T _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev
(standard input):         U _ZN6QDebugD1Ev

另一个尝试:

find -iname '*.so*' -exec nm {} \; -exec grep _ZN6QDebugD1Ev {} \;

这行不通,因为这两个 exec 是完全独立的。

我该怎么办?

【问题讨论】:

    标签: bash grep find nm


    【解决方案1】:

    将“-A”选项传递给 nm,它将在其输出前加上文件名。然后只需 grep 查找您感兴趣的符号,例如:

    find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev
    

    【讨论】:

    • plus 1. 为了提高效率,在支持它的系统上,将\; 替换为+
    • 不错的@John1024 - 我必须记住这一点!
    猜你喜欢
    • 1970-01-01
    • 2017-08-02
    • 2016-09-28
    • 1970-01-01
    • 2021-07-22
    • 2012-05-14
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多