Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a .obj file?

In visual studio a object file (.obj) is generating after compiling a c++ file. How to read and understand it? Also how to see the code after compiler optimization in Visual studio 2015. Please redirect if this is already answered.

like image 971
snb Avatar asked Aug 03 '17 07:08

snb


2 Answers

Use the DUMPBIN tool from Visual Studio command prompt. Specifically, the /DISASM option shows you the disassembly. Do note the if you have link-time optimization enabled, then at least theoretically the final code may change after the .obj files are linked to form the final binary (.exe or .dll). You can disassemble those with DUMPBIN as well.

like image 96
cynic Avatar answered Sep 21 '22 19:09

cynic


You're sort of asking the wrong question: you say you want to see compiler optimizations but then you draw conclusions leading you to think you .obj files are required for that. That works, as cynic's answer shows, but there are alternatives which can be handier/better depending on the situation:

  • run code under the debugger, break, right-click any source file, select 'Go To Disassembly' and you can view source and assembly inline
  • have the compiler output assembly code (again optionally including source and machine code): go to project settings->Compiler->Output Files and set 'Assembler Output'
like image 26
stijn Avatar answered Sep 21 '22 19:09

stijn