Thread View: comp.sys.next.programmer
2 messages
2 total messages
Started by Nelson Minar
Tue, 14 Apr 1992 22:18
How do I override malloc with the C compiler?
Author: Nelson Minar
Date: Tue, 14 Apr 1992 22:18
Date: Tue, 14 Apr 1992 22:18
30 lines
1741 bytes
1741 bytes
I'm compiling a simple stdio-only program on a NeXT box. One of the
modules of the program is my own version of malloc(), free(), and
realloc().
When I go to link my program, I get errors from the linker claiming
that malloc() is redefined. If I don't link in my own version of
malloc(), it links fine, albeit without the code I want.
The NeXT OS is the first system I've gotten these errors - most OSs
will use my malloc() and never link in the standard malloc(). From
what I've read of the ld man page, it should work the way I want it
to. I'm guessing the problem is general - how do I override standard
library routines in C code? I'd prefer email responses.
cc -o main main.o malloc.o
/bin/ld: multiple definitions of symbol _realloc
malloc.o definition of _realloc in section (__TEXT,__text)
/lib/libsys_s.a(malloc.o) definition of absolute _realloc (value 0x5002d7a)
/bin/ld: multiple definitions of symbol _malloc
malloc.o definition of _malloc in section (__TEXT,__text)
/lib/libsys_s.a(malloc.o) definition of absolute _malloc (value 0x50028fa)
/bin/ld: multiple definitions of symbol _free
malloc.o definition of _free in section (__TEXT,__text)
/lib/libsys_s.a(malloc.o) definition of absolute _free (value 0x5002546)
cc -o main main.o
[no errors]
--
__
nelson@reed.edu \/ Shop as usual and avoid panic buying
Re: How do I override malloc with the C compiler?
Author: Nelson Minar
Date: Wed, 15 Apr 1992 19:43
Date: Wed, 15 Apr 1992 19:43
28 lines
1599 bytes
1599 bytes
In article <1992Apr14.221833.13899@reed.edu> I ask:
>When I go to link my program, I get errors from the linker claiming
>that malloc() is redefined. If I don't link in my own version of
>malloc(), it links fine, albeit without the code I want.
>The NeXT OS is the first system I've gotten these errors - most OSs
>will use my malloc() and never link in the standard malloc().
Thanks to Usenet once again for quick replies.
N Tomczak-Jaegermann <ntomczak@vega.math.ualberta.ca> kindly told me:
>This issue was rehashed in this newsgroup already. Unfortunately
>nobody seems to know a good answer and NeXT is totally numb on the
>issue. This has to do with how shared libraries are organized. The
>only option you really have is to rename your routines and calls to
>them.
If anyone can tell me how to get around this linker problem without
having to rename my routines, I'd really appreciate it. I hate kludges
like "#define malloc My_Malloc_I_Hope_This_Name_Isnt_In_The_Library".
One more reason why I don't want to use a NeXT box...
--
__
nelson@reed.edu \/ You stupid vulgar greedy ugly American death sucker
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads