I am using dlopen to merge symbols of a dynamically loaded library and its host, and in the host I have a class:
class Foo {
public:
Foo() {/* ... */}
void bar() {/* ... */}
};
int main() {
// Foo foo;
return 0;
}
I am compiling this with g++ -Wl,--export-dynamic -o test test.cpp
and inspecting the symbols with nm -g test
.
I expect the symbols _ZN3FooC1Ev
and _ZN3FooC2Ev
to exist in the executable, since the dynamic library needs them, but they do not appear unless I use them by un-commenting the above line. I believe it is being optimized out, since GCC thinks it is not needed.
How do I force the constructor and methods of Foo to be included in the host binary?
A class definition with inlined method definitions do not generate any symbol if you don't, at least, define an object. So don't define the methods as inlined if you want to ensure their visibility...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With