What does an object file contain?

后端 未结 8 977
长情又很酷
长情又很酷 2020-12-13 06:14

During the various stages of compilation in C or C++, I know that an object file gets generated (i.e., any_name.o file). What does this .o file contain? I can\'t open it sin

8条回答
  •  余生分开走
    2020-12-13 06:28

    Use the file command for things like this. It's an ELF object file on a modern Linux system. E.g. if compiled for 32-bit x86.

    ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
    

    In contrast, a dynamically linked executable might look like:

    ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
    

    To see headers, including section names, you can use:

    objdump -x any_name.o
    

    To disassemble:

    objdump -d any_name.o
    

提交回复
热议问题