g++ -c xyz.cpp
creates an object file
But when I open it in vim editor it shows some crazy text...
How can I see the machine code?
What package can use to open and see that machine code?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Check out the
In it you'll find objdump - display information from object files.
Then try running
objdump -d xyz.o.
Machine code generated by your compiler is not supposed to be human readable, but rather completely optimized to run as fast as possible on your processor.
However, you can read symbols from the binary files like this:
$ nm main.o | c++filt U _Unwind_Resume U FactoryImpl::FactoryImpl() U UI::UI(Subject*) U operator delete(void*) U operator new(unsigned long) U __gxx_personality_v0 0000000000000000 T main
c++filtare from the
binutilspackage you probably have already when developing.
I just realized my answer wasn't really answering your question about reading the actual machine code. However, I think it provides some useful information instead. For reading the assembly-level operations for your processor, use
objdump -d as proposed by @hnasarat
You should use the
-S flag to make the compiler output assembly code.
So for your example the code would be
g++ -S xyz.cpp and the assembly would be printed in