I want to create a library with a modified version of printf and then call LD_PRELOAD so when my program calls printf it uses my version. Can someone explain to me how to use LD_PRELOAD and if there is a something special I need to do in my code or my library?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
That seems like a bad idea. Why not name your version of
printf
something else?You just set the environment variable
LD_PRELOAD
to the full path to the replacement library. Since all programs you launch after that point will attempt to use this library, you may want to make a wrapper script that setsLD_PRELOAD
then calls the program you want to run.LD_PRELOAD
and shadowing should be deal with extream care. I remember discovering bug in shadowingg_malloc
in gpgme code (or other related to gpg) as the GLib internals changed.The simple answer is - don't do it. The more complicated - do it if and only if you have to - and usually you don't (unless you write some sort of debugging software).