Linux shared library: replace symbol runtime

I have a quite large C application consisting of several shared libraries. One of the core libraries has a function

void common_function(const char * arg) { ... }

Which is called by all the other libraries. During testing I would like to use a different test implementation of the common_function.

My plan has been to create a test library containing the alternate implementation of common_function; is it at all possible to replace the default common_function runtime using dlopen() / dlsym() trickery, or alternatively would this link line:

gcc -o test.c -ltest -lcommon

ensure that the common_function implementation in was used also in the - altough the latter has it's own implementation of common_function.


Read Drepper's paper: How To Write Shared Libraries and wikipage on dynamic linker.

You probably want to play the LD_PRELOAD trick (assuming all your libraries are shared, not static).

Need Your Help

Regular expression in Perl for G729A+B

regex perl

I'm new to Perl. I'm unable to do the regular expression match for the below fields.

Factor Loadings using sklearn

python scikit-learn pca

I want the correlations between individual variables and principal components in python.