c++ read - How to view symbols in object files?
linux objdump (5)
How can I view symbols in a .o file? nm does not work for me. I use g++/linux.
nm, you can use the powerful
objdump. See the man page for details. Try
objdump -t myfile or
objdump -T myfile. With the
-C flag you can also demangle C++ names, like
nm you_obj_file.o | c++filt
There is a command to take a look at which functions are included in an object file or library or executable:
Have you been using a cross-compiler for another platform? If so, you need to use the respective
For example, if you have used
XXX-YYY-gcc to compile the .o file, you need to use
XXX-YYY-objdump to process the files.
It might help if you know little bit of internals...
- C++ compiler already knows how to convert scaler types such as float to int. Use
- In general case of converting from type
B's constructor passing
Aas param. If
Bdoesn't have such constructor then you get compile time error.
- Cast from
B*always succeeds if A and B are in inheritance hierarchy (or void) otherwise you get compile error.
- Gotcha: If you cast base pointer to derived pointer but if actual object is not really derived type then you don't get error. You get bad pointer and segfault at runtime. Same goes for
- Gotcha: Cast from Derived to Base or viceversa creates new copy! For people coming from C#/Java, this can be a huge surprise.
- dynamic_cast uses runtime type information to figure out if cast is valid. For example,
(Derived*)may fail if pointer is not actually of derived type.
- This means, dynamic_cast is very expensive compared to static_cast!
B*, if cast is invalid then dynamic_cast will return nullptr.
B&if cast is invalid then dynamic_cast will throw bad_cast exception.
- Unlike other casts, there is runtime overhead.
- While static_cast can do non-const to const it can't go other way around. The const_cast can do both ways.
- One example where this comes handy is iterating through some container like
set<T>which only returns its elements as const to make sure you don't change its key. However if your intent is to modify object's non-key members then it should be ok. You can use const_cast to remove constness.
- Another example is when you want to implement
T& foo()as well as
const T& foo(). To avoid code duplication, you can apply const_cast to return value of one function from another.
- This basically says that take these bytes at this memory location and think of it as given object.
- For example, you can load 4 bytes of float to 4 bytes of int to see how bits in float looks like.
- Obviously, if data is not correct for the type, you may get segfault.
- There is no runtime overhead for this cast.