[英]c++ functions defined inside class declaration don't show up as linker symbols
Here's my C++ class, part defined inside class and part outside. 这是我的C ++类,部分在类内部定义,而部分在外部定义。 The problem: doing nm reveals that functions defined in the class declaration don't show up in object file, but those outside do.
问题是:执行nm揭示类声明中定义的函数未显示在目标文件中,而外部函数显示在目标文件中。 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.
我正在使用g ++ 4系列。
class A {
public:
void this_will_not_show_up() { };
void this_will_show_up();
};
void A::this_will_show_up() { }
The functions that are defined inline in the class definitions are compiled as inline functions ie 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.
像STL这样的库几乎完全只作为标头实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.