delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/15/01:48:59

Message-ID: <3857355F.CA2254D5@gs707.com>
Date: Wed, 15 Dec 1999 09:29:52 +0300
From: Alexey Zakhlestine <alx AT gs707 DOT com>
X-Mailer: Mozilla 4.7 [en] (Win95; I)
X-Accept-Language: ru
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: is 'ld --wrap' not for C++?
References: <3856A623 DOT 14E00791 AT yahoo DOT com>
Reply-To: djgpp AT delorie DOT com

Well.... astually AFAIK "free" and "malloc" are C-routines.... not C++

In C++ you should use new/delete

Sven Sandberg wrote:

>
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> Hello,
>
> I can't get the linker command --wrap to work with C++. The following
> program compiles perfectly if I name it test.c, but produces linker
> errors if I name it test.cc. Does --wrap only work with C, or am I doing
> something wrong? I couldn't find anything in the docs saying it
> shouldn't work. (FYI, gcc -v says "gcc version 2.95.1 19990816
> (release)"). Here is my program, the command line and the error
> messages:
>
> -------- 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'
> d:/djgpp/lib/libgcc.a(frame.o): In function `frame_init':
> frame.c(.text+0x3fe): undefined reference to `__wrap_malloc'
> frame.c(.text+0x40a): undefined reference to `__wrap_malloc'
> d:/djgpp/lib/libgcc.a(frame.o): In function `execute_cfa_insn':
> frame.c(.text+0x8d6): undefined reference to `__wrap_malloc'
> d:/djgpp/lib/libgcc.a(frame.o): In function `__register_frame':
> frame.c:627: undefined reference to `__wrap_malloc'
> d:/djgpp/lib/libgcc.a(frame.o):frame.c:627: more undefined references to
> `__wrap_malloc' follow
> collect2: ld returned 1 exit status
> make.exe: *** [test.exe] Error 1
> -------- end of error messages --------
>
> Thanks for help,
> Sven Sandberg

- Raw text -


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