Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-20-2010, 02:37 PM   #1
LQ Newbie
Registered: Feb 2010
Posts: 1

Rep: Reputation: 0
using ld -wrap function to instrument

Hi All,

I am trying the wrap feature for the first time. I followed the instruction as mentioned in this link

but I am getting an error saying "undefine reference to __wrap_malloc

I followed all the steps, but the post was a decade old, I am sure something has changed? or am I missing something.

Appreciate your time in help me out!
Old 02-22-2010, 07:48 AM   #2
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67

I checked this feature on my system, and it works perfectly. This is what I did:

#include <stdio.h>
#include <stdlib.h>

void *__real_malloc(size_t);

void *__wrap_malloc(size_t c)
        printf("My MALLOC called: %d\n", c);
        return __real_malloc(c);

int main (int argc, char *argv[])
        void *ptr = malloc(12);

        return 0;
And I compiled & run the code with:

[gcc wrap]$ gcc wrap.c -o wrap -Wl,-wrap,malloc
[gcc wrap]$ ./wrap
My MALLOC called: 12
I'm using

* gcc 4.4.3
* binutils

Maybe, you could post your code ...

- Andi -
Old 12-03-2010, 01:04 AM   #3
LQ Newbie
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
May be your code needs extern C


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you play a musical instrument? PatrickMay16 General 25 01-07-2010 12:44 PM
pdf reader instrument linuxsavar General 2 05-16-2007 10:04 AM
"enscript --word-wrap" does not wrap line of text file powah Linux - General 3 05-16-2006 09:12 PM
Do you play any instrument? Eits0 General 50 11-13-2005 02:38 PM
Does anybody else play an instrument? Joey.Dale General 25 10-27-2004 09:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration