title: How to wrap a C++ function?
body: <p>I'm trying to wrap a <code>c++</code> function called <code>i_receive()</code> by following <a href="http://samanbarghi.com/blog/2014/09/05/how-to-wrap-a-system-call-libc-function-in-linux/" rel="nofollow noreferrer">this</a> tutorial, I first created a <code>wrap.c</code> file, the content of this file is like this:</p>
  
  <pre><code>int i_receive(const uint32_t *f, int32_t t){
  
      static int (*real_i_receive)(const uint32_t *, int32_t)=NULL;
      printf("hello world");
      return real_i_receive;
  }
  </code></pre>
  
  <p>I compiled this file with <code>gcc -fPIC -shared -o wrap.so wrap.c -ldl</code>, when I used the <code>LD_PRELOAD</code> to run some C++ code with <code>LD_PRELOAD=/full/path/to/wrap.so ./mycppcode</code> I got this message:</p>
  
  <blockquote>
    <p>ERROR: ld.so: object '/full/path/to/wrap.so' from LD_PRELOAD cannot be preloaded: ignored`.</p>
  </blockquote>
  
  <p>I was guessing the reason might be that the wrap file is a C file, and I'm using it with C++ code, am I right?</p>
  
  <p>I changed the file to <code>wrap.cc</code> with the same content, when compiling in the same way as before, I got:</p>
  
  <blockquote>
    <p>ERROR: invalid conversion from <code>'int (*)(const uint32_t*, int32_t)' to 'int'</code></p>
  </blockquote>