delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/15/03:23:28

Date: Wed, 15 Dec 1999 09:12:01 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Sven Sandberg <ssven DOT geo AT yahoo DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: is 'ld --wrap' not for C++?
In-Reply-To: <3856A623.14E00791@yahoo.com>
Message-ID: <Pine.SUN.3.91.991215091045.18491J-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 14 Dec 1999, Sven Sandberg wrote:

> -------- source file: test.cc ---------
> #include <stdlib.h>
> extern void *__real_malloc(size_t size);
> void *__wrap_malloc(int c)
> {
>    return __real_malloc(c);
> }
> int main(void)
> {
>    free(malloc(4711));
>    return 0;
> }
> -------- eof(test.cc) -----------------
> 
> command line:
>    gcc -Wl,--wrap,malloc -o test.exe test.cc -W -Wall
> 
> -------- error messages ---------------
> test.o(.text+0xe):test.cc: undefined reference to
> `__real_malloc(unsigned long)'
> test.o(.text+0x33):test.cc: undefined reference to `__wrap_malloc'

I think both __wrap_malloc and __real_malloc should be declared as
``extern "C"'' in a C++ program.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019