Question: 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?

Answer: 
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...
In order to generate dynamicaly loaded libraries you habe to build it with: 

```
$ gcc -shared -fPIC -o lib1.so lib1.c

```

**-fPIC** is used to tell GCC to produce Position Independent Code.  

-**shared** is used to indicate it’s a shared object

To link against your library test.so you can use the following: 

```
$ gcc -L$(pwd) -Wl,-rpath=$(pwd) --enable-new-dtags -o test main.c -l1 -l2

```

With **-rpath=/my/location** you tell the linker the list of alternate locations  

To verify the dynamic section of your binary you can use:`$ readelf -d test`