How to redefine malloc() in Linux for use in C++ new
问题 I have a mem_malloc() and mem_free() defined for me and I want to use them to replace the malloc() and free() and consequently C++'s new and delete. I define them as follows: extern "C" { extern void *mem_malloc(size_t); extern void mem_free(void *); void * malloc(size_t size) { return mem_malloc(size); } void free(void *memory) { mem_free(memory); } } However, I get two link errors: [user@machine test]$ g++ -m32 -pthread main.cpp -static libmemnmf-O.a /usr/lib/../lib/libc.a(malloc.o): In