How stub functions in C++ are used are replaced by shared library functions

2.6k views Asked by At

I am new to how C++ stubs functions are used .

I went through the link How to create stub shared libraries on Linux but

1) I could not get exact complete example code in c++ in which stubs are written in C++ code . If someone can point me to exact sample example?

2) Also I was looking how exactly the stubs are replaced by exact same name shared library functions on Linux?

It will be helpful if someone can help me in my two questions.

2

There are 2 answers

1
Chris On

The answer to your question comes with an understanding of the black art of dynamic linking. Read Ulrich Drepper's How to Write Shared Libraies for a thorough treatment of the subject.

0
Chris Dodd On

To answer your questions directly:

1) Stubs are not written in C++. Stubs are created by the linker automatically whenever you link a program against a shared library. They're not associated with any particular language; the linker creates them as binary/asm stubs directly from each symbol based solely on the symbol name.

2) The dynamic linker replaces/rewrites the stubs to call the actual dynamic library code that was found at runtime.