Take the 2-minute tour ×

Here's my C++ class, part defined inside class and part outside. The problem: doing nm reveals that functions defined in the class declaration don't show up in object file, but those outside do. What should I do to make the symbols inside the class turn up in the object file as well? I am using g++ 4 series.

class A {
    void this_will_not_show_up() { };
    void this_will_show_up();
void A::this_will_show_up() { }
share|improve this question
Don't use inline methods ;)? –  paulsm4 Apr 17 '13 at 3:23
is it must to define them inside class? –  mag Apr 17 '13 at 3:28
These are part of some shared lib I am using, I don't have much control here. –  Fanatic23 Apr 17 '13 at 3:34
Why would you want them show up in the object file? The linker does not need them. –  n.m. Apr 17 '13 at 3:54

1 Answer 1

up vote 0 down vote accepted

The functions that are defined inline in the class definitions are compiled as inline functions i.e. the code in this functions is 'copied' to the calling functions. Therefore you don't have any dedicated implementation of the inline function and there is no linker symbol.

When you define the method non-inline in a compilation unit it may be that this function is called from a different compilation unit. Therefore this implementation requires functions that can be linked. The compiler just generates a function including a header and a (decorated) name that you find in the linker map.

It's no problem when you using this in a shared lib since all what your compiler needs to use is defined in the header files. There are libraries like the STL that are nearly completely implemented as header only.

share|improve this answer

Your Answer


