delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/14/16:30:25

Sender: svsa1977 AT delorie DOT com
Message-ID: <3856A623.14E00791@yahoo.com>
Date: Tue, 14 Dec 1999 21:18:43 +0100
From: Sven Sandberg <ssven DOT geo AT yahoo DOT com>
X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.6 sun4u)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: is 'ld --wrap' not for C++?
Reply-To: djgpp AT delorie DOT com

 	
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