3

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 libtest.so was used also in the libcommon.so - altough the latter has it's own implementation of common_function.

user422005
  • 1,840
  • 15
  • 30

1 Answers1

1

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).

Community
  • 1
  • 1
Basile Starynkevitch
  • 216,767
  • 17
  • 275
  • 509