0

I wrote a c program by calling the function "printf" and "sqrt". I use gcc(Apple clang version 12.0.0) to compile it without any linked library, and it works. So I want to see which lib is dependent on it. I exec otool -L a.out, and the result is that: /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1). So I want to see if those two functions, printf and sqrt, are defined in this lib, then I exec nm /usr/lib/libSystem.B.dylib | grep printf. However, there is nothing output as well as sqrt. I just want to know why the symbols of printf and sqrt are not in the libSystem.B.dylib, or there is something strange happening when gcc link the lib in macOS?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Note that there is no file `/usr/lib/libSystem.B.dylib`. – fuz Aug 15 '21 at 11:56
  • Not sure about MacOS, but on my system you have to use `nm -D` to see dynamic symbols. Otherwise you only see "normal" symbols and a dynamic library typically doesn't have any. – Nate Eldredge Aug 15 '21 at 13:18
  • @NateEldredge macOS `nm` doesn't have a `-D` option it seems. Also, this file doesn't exist. – fuz Aug 15 '21 at 13:54
  • @nobody Ah yes, I only checked on Big Sur. Now on to find the shared cache... – fuz Aug 15 '21 at 14:37
  • Please show us how you linked your program. Commonly some standard libraries are automatically linked, and `printf()` and `sqrt()` might be added statically. – the busybee Aug 16 '21 at 06:51

0 Answers0