[cfe-dev] "::malloc not found"

Joerg Sonnenberger joerg at britannica.bec.de
Fri May 11 15:26:43 PDT 2012

On Fri, May 11, 2012 at 01:12:06PM -0400, Martin C. Martin wrote:
> Hi,
> I can compile libmemcached-1.0.5 just fine with gcc/g++ (on Ubuntu 
> 12.04).  But when I try with Clang 3.0 I get:
>    CXX    libmemcached/csl/libmemcached_libmemcached_la-context.lo
> In file included from libmemcached/csl/context.cc:38:
> In file included from ./libmemcached/csl/common.h:40:
> In file included from ./libmemcached/common.h:49:
> /usr/include/c++/4.6/cstdlib:118:11: error: no member named 'malloc' in 
> the global namespace
>    using ::malloc;
>          ~~^
> /usr/include/c++/4.6/cstdlib:126:11: error: no member named 'realloc' in 
> the global namespace
>    using ::realloc;
>          ~~^
> Any pointers on whether this is a Clang or libmemcached problem?  It 
> compiles just fine with gcc after all...

glibc headers can be strange and gcc headers can be strange, so
"compiles fine with gcc" is not a very useful metric. I suggest you
start by using adding -save-temps and check when malloc/realloc are
defined. One item to look for: stray extern "C" blocks. GCC seems to
implicitly switch back to C++ mode for the C++ system headers, Clang


More information about the cfe-dev mailing list