Let's say I have two files:
// shared.c (will be compiled to 'shared.so')
#include <stdio.h>
int f() { printf("hello\n"); }
and
// exe.c (will be compiled to 'exe')
#include <stdio.h>
int f();
int main() {
int i;
scanf("%d", &i);
if (i == 5) f();
}
I compile both files as following:
gcc -shared shared.c -o libshared.so
gcc exe.c -o exe -lshared -L.
When I run exe
and type 5, it will call f and then exit. However, if I delete f
from shared.c
and recompile it I will get a runtime symbol lookup error only if I type 5. Is there a way that I can check that exe
has all its symbols that will work independent of user input in this case? Preferrably without running it.
You can use
ldd -r exe
command to list the shared library dependencies. Here is my output for your example without thef
function:(Don't mind the
LD_LIBRARY_PATH=.
part. It is used to tell to look for shared libraries in the current directory)