gcc
obtains the function definitions from the C library. You could determine the path that gcc
would look into, by default, for it by saying:
ld --verbose | grep SEARCH_DIR
This leads to /usr/lib
on my system.
Lets try to find if the library contains the symbol for a standard function, say scanf
:
nm -A /usr/lib/libc.so | grep scanf
The results include:
/lib/libc.so:0000000000042a90 T scanf
Consider a small example:
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
Lets call it i.c
:
$ gcc i.c # Compile
$ ldd ./a.out # Try to find dependencies
./a.out:
-lc.12 => /usr/lib/libc.so.12
The last command essentially implies that the binary depends upon /usr/lib/libc.so.12
and that you'd find the definitions of the functions used in the code therein.