Can I get a report of ALL the libraries linked when building my C++ executable (gcc)? (including statically linked)

后端 未结 5 947
灰色年华
灰色年华 2021-01-30 17:29

I have a C++ application that I inherited, which consists of:

  • My main app
  • Several app-specific libraries (libapp1, libapp2, etc...)
  • Several \"thi
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 18:11

    I'll answer your second question first. You can simply use the -H or -M flag to see all (including system) headers processed in the compilation. gcc -H main.c should do the trick. Seeing which headers are included will actually get you on the right track to finding which static libraries were linked in.

    You could use objdump on your final object (or readelf on your final binary) to get the names of all the functions in there. You'd then have to go find the libraries from which the functions were pulled in, but that's a bit cumbersome. You'd definitely have to make a script to minimize the pain.

    Someone else mentioned using gcc -Wl,-verbose which simply passes the -verbose flag to the linker. That's a perfect way to get a list of shared libraries (.so files), but you said yours are static, so that isn't the way to go in this case.

    Good luck!

提交回复
热议问题