title: LD_PRELOAD not working with my program
body: <p>For testing LD_PRELOAD, I wrote my own <code>getpid</code>, which prints something before calling the original <code>getpid</code> using dlsym. The code is given below.</p>
  
  <pre><code>#define _GNU_SOURCE
  
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;dlfcn.h&gt;
  
  typedef pid_t (*getpidType)(void);
  
  pid_t getpid(void)
  {
      printf("Hello, getpid!\n");
      getpidType f = (getpidType)dlsym(RTLD_NEXT, "getpid");
      return f();
  }
  </code></pre>
  
  <p>However when I use such <code>getpid</code> in my program and run it using LD_PRELOAD, by typing <code>LD_PRELOAD=./prelib.so ./prog</code>,  I get the following error. </p>
  
  <pre><code>./prog: symbol lookup error: ./prelib.so: undefined symbol: dlsym
  </code></pre>
  
  <p>But If I do <code>LD_PRELOAD=./prelib.so bash -c 'echo $$'</code>, there is no such error. Any idea what is going on here.</p>