7

I'm struggling with the right command to do the following:

find all shared libraries (*.so) that contain a certain symbol.

This is what I've tried:

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

The above gives some output with symbols found, but doesn't pinpoint the filename that the symbol occurred in. Any flag that I give to grep to tell it to print a filename is lost because grep is being fed from stdin.

(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

Another attempt:

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

This doesn't work because the two execs are completely independent.

What should I do?

Rich von Lehe
  • 1,362
  • 2
  • 16
  • 38

1 Answers1

13

Pass the "-A" option to nm which will prefix its output with the filename. Then just grep for the symbol you're interested in, for example:

find -iname '*.so*' -exec nm -A {} \; | grep _ZN6QDebugD1Ev
bgstech
  • 624
  • 6
  • 12