Use __wrap_malloc in a shared library
I created a shared library in Linux that calls malloc wrapper which is the __wrap_malloc.
void * __wrap_malloc( size_t size )
{
printf("Test\n");
return __re开发者_运维百科al_malloc( size );
}
Then the shared library was generated successfully.
But when I use the shared library and build the application. The linker gives me "undefined" error message,
undefined reference to `__wrap_malloc'
Is is possible to call __wrap_malloc() function in a shared library?
Please advice.
Many thanks.
You are probably not using the --wrap option to ld correctly. Without more information about what command line you were using it is impossible to determine what was going wrong.
精彩评论