c - Detecting unresolved symbols in an ELF executable -


let's have 2 files:

// shared.c (will compiled 'shared.so') #include <stdio.h> int f() { printf("hello\n"); } 

and

// exe.c (will compiled 'exe') #include <stdio.h> int f(); int main() {      int i;     scanf("%d", &i);     if (i == 5) f();  } 

i compile both files following:

gcc -shared shared.c -o libshared.so gcc exe.c -o exe -lshared -l. 

when run exe , type 5, call f , exit. however, if delete f shared.c , recompile runtime symbol lookup error if type 5. there way can check exe has symbols work independent of user input in case? preferrably without running it.

you can use ldd -r exe command list shared library dependencies. here output example without f function:

$ ld_library_path=. ldd -r ./exe         linux-vdso.so.1 (0x00007ffcfa7c3000)         libshared.so => ./libshared.so (0x00007f303a02e000)         libc.so.6 => /lib64/libc.so.6 (0x0000003e26c00000)         /lib64/ld-linux-x86-64.so.2 (0x0000003e26400000) undefined symbol: f     (./exe) 

(don't mind ld_library_path=. part. used tell shared libraries in current directory)


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -