Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking if a binary compiled with "-static"

Tags:

linux

static

gcc

I have a binary file in linux. How can I check whether it has been compiled with "-static" or not?

like image 427
mahmood Avatar asked Nov 07 '11 18:11

mahmood


People also ask

How do you tell if an executable is statically linked?

file source code /* * Look through the program headers of an executable image, searching * for a PT_INTERP section; if one is found, it's dynamically linked, * otherwise it's statically linked.

How to check static libraries in executable?

nm <exe filename> shows the symbols in the file. To see which symbols come from static libraries requires running nm against those libraries to get a list of the symbols (functions, etc.) in them, then comparing them to what your list of symbols from nm <exe filename> . You compare lists with the comm command.

How do I know if my library is static or dynamic?

Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

What is a statically linked binary?

Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is both faster and more portable, since it does not require the presence of the library on the system where it is run.


2 Answers

ldd /path/to/binary should not list any shared libraries if the binary is statically compiled.

like image 196
lanzz Avatar answered Sep 18 '22 16:09

lanzz


You can also use the file command (and objdump could also be useful).

like image 37
Basile Starynkevitch Avatar answered Sep 18 '22 16:09

Basile Starynkevitch