私はmem_malloc()とmem_free()を定義していますので、malloc()とfree()を置き換えてC++の新しい削除する。C++での使用のためにLinuxでmalloc()を再定義する方法new
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);
}
}
をしかし、私は2つのリンクエラーを取得し、:次のように
は、私はそれらを定義
[[email protected] test]$ g++ -m32 -pthread main.cpp -static libmemnmf-O.a
/usr/lib/../lib/libc.a(malloc.o): In function `free':
(.text+0x153c): multiple definition of `free'
/tmp/ccD2Mgln.o:main.cpp:(.text+0x842): first defined here
/usr/lib/../lib/libc.a(malloc.o): In function `malloc':
(.text+0x3084): multiple definition of `malloc'
/tmp/ccD2Mgln.o:main.cpp:(.text+0x856): first defined here
libmemnmf-O.a(mem_debug.o): In function `mem_init_debug_routines':
mem_debug.c:(.text+0x83c): undefined reference to `dlopen'
mem_debug.c:(.text+0x89d): undefined reference to `dlsym'
mem_debug.c:(.text+0xa03): undefined reference to `dlclose'
mem_debug.c:(.text+0xa24): undefined reference to `dlclose'
mem_debug.c:(.text+0xa2e): undefined reference to `dlerror'
collect2: ld returned 1 exit status
1)私は、多重定義されたのmalloc()とfree()のエラーを取得するにはどうすればよいです私の定義を取って、組み込まれたものではなくて、ただ取り除くだけです。
2)dlopen()とフレンドを提供するライブラリは何ですか?私はこれが組み込まれていると思うだろうが、それらは未定義である。
新しいと削除mallocを呼び出す必要はありません。 –