Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

something happened to malloc?

93 views
Skip to first unread message

Torsten Mueller

unread,
Feb 18, 2015, 3:29:25 AM2/18/15
to
My C++ application compiled for many years with gcc, up to current
version 4.9.2. But now after a compiler update it suddenly says "malloc
is undefined", and this message comes from far above, from inside the
cstdlib header.

Note: I don't use malloc at all, not a single time. My code is proper
C++. But C++ himself uses malloc in the new operator.

What I had to do for getting a workaround was to include stdlib.h before
cstdlib - but can this be the solution??? cstdlib still includes
stdlib.h, of course, it always did.

In my application I use also boost (1.57). And boost has an own cstdlib
header. Could this be the reason?

Has anyone had this problem in the last time, malloc is undefined?

T.M.

Lőrinczy Zsigmond

unread,
Feb 18, 2015, 3:47:56 AM2/18/15
to
Please quote the complete message,
it's not clear if this is a compiler-message or a linker-message.

Øyvind Røtvold

unread,
Feb 18, 2015, 3:56:10 AM2/18/15
to
Torsten Mueller <muel...@runbox.com> writes:

> My C++ application compiled for many years with gcc, up to current
> version 4.9.2. But now after a compiler update it suddenly says "malloc
> is undefined", and this message comes from far above, from inside the
> cstdlib header.
>
> Note: I don't use malloc at all, not a single time. My code is proper
> C++. But C++ himself uses malloc in the new operator.
>
> What I had to do for getting a workaround was to include stdlib.h before
> cstdlib - but can this be the solution??? cstdlib still includes
> stdlib.h, of course, it always did.

Is cstdlib supposed to be self-contained? If so try to include it
first in your source file. If it fails there's an error in your
compiler which should be reported - or, more likely, an error in your
compiler installation that you should fix.


>
> In my application I use also boost (1.57). And boost has an own cstdlib
> header. Could this be the reason?

If you include this cstdlib header then anything boost think proper
could happen, including what you describes. Remove boots from the
equation and try again.

>
> Has anyone had this problem in the last time, malloc is undefined?
>
> T.M.

--
.. Ųyvind - soon to appear in a kill file near you.
.. Ignorance can be cured; stupidity is forever.

Torsten Mueller

unread,
Feb 18, 2015, 4:07:34 AM2/18/15
to
Lőrinczy Zsigmond <zs...@nospam.for.me> schrieb:

> Please quote the complete message,
> it's not clear if this is a compiler-message or a linker-message.

Sure it is clear. I never spoke about the linker, I spoke about the
compiler and headers. It's a true compiler problem, happening again and
again in every single source file.

T.M.

Lőrinczy Zsigmond

unread,
Feb 18, 2015, 4:16:12 AM2/18/15
to
> > > But now after a compiler update it suddenly says
> > > "malloc is undefined"

> > Please quote the complete message,

> It's a true compiler problem,
> happening again and again in every single source file.

That's why you don't quote the complete message. Ok.

Torsten Mueller

unread,
Feb 18, 2015, 4:19:19 AM2/18/15
to
Øyvind Røtvold <orot...@gmail.com> schrieb:

> Is cstdlib supposed to be self-contained?

I'm sure.

> If it fails there's an error in your compiler which should be reported
> - or, more likely, an error in your compiler installation that you
> should fix.

I try to get a preprocessor output this afternoon to see the real code
and which header is really included and which conditional code is indeed
compiled.

Interesting is that cstdlib also uses a handful of other primitive
C-functions, about 20, but only malloc is unknown.

T.M.

Torsten Mueller

unread,
Feb 18, 2015, 4:21:43 AM2/18/15
to
Lőrinczy Zsigmond <zs...@nospam.for.me> schrieb:

>> > Please quote the complete message,
>
>> It's a true compiler problem,
>> happening again and again in every single source file.
>
> That's why you don't quote the complete message. Ok.

Dear Hungarian friend, I can't quote because I'm currently not on this
machine, OK?

T.M.

Lőrinczy Zsigmond

unread,
Feb 18, 2015, 5:04:41 AM2/18/15
to
On 2015-02-18 09:29, Torsten Mueller wrote:
> In my application I use also boost (1.57). And boost has an own cstdlib
> header. Could this be the reason?

But of course. Try to complie boost-less example programs.

David Brown

unread,
Feb 18, 2015, 5:39:13 AM2/18/15
to
The usual way to proceed with this sort of thing is to figure out a
minimum sample that demonstrates the problem - this should help you
figure out if boost is the problem or there is something else wrong.
And then you can post the example along with the error messages (when
you are on the right computer, of course). Also include details of the
compiler and command-line switches.

You said that your code worked with gcc up to 4.9.2 - but after an
update it failed. Since 4.9.2 is the latest released version of gcc,
are you trying a development version? Did you get the new version from
a different place (in which case it might be packaged with different
libraries or other differences)?

Torsten Mueller

unread,
Feb 18, 2015, 6:10:54 AM2/18/15
to
David Brown <david...@hesbynett.no> schrieb:

> You said that your code worked with gcc up to 4.9.2 - but after an
> update it failed. Since 4.9.2 is the latest released version of gcc,
> are you trying a development version?

No, it's official 4.9.2. But on a Linux machine you always have still
other parts of software defining the concrete build environment,
especially glibc and libc++ (and a lot of others ...)

My situation is as follows: I have two Linux machines, an old one and a
new one, both with gcc 4.9.2, but with a different bunch of libs. The
old one compiles fine, the new one doesn't know malloc in cstdlib. Sure
I have glibc on this machine, sure I have also all the glibc-headers,
sure malloc is an existing, documented and well known function. I never
changed anything in these files or in the permissions, all is standard,
but cstdlib doesn't know malloc.

OK, for me it's a hint that noone says, yes, that's right, they changed
something last sunday in glibc, malloc is banned for ever, or so.

T.M.

David Brown

unread,
Feb 18, 2015, 7:10:30 AM2/18/15
to
On 18/02/15 12:10, Torsten Mueller wrote:
> David Brown <david...@hesbynett.no> schrieb:
>
>> You said that your code worked with gcc up to 4.9.2 - but after an
>> update it failed. Since 4.9.2 is the latest released version of gcc,
>> are you trying a development version?
>
> No, it's official 4.9.2. But on a Linux machine you always have still
> other parts of software defining the concrete build environment,
> especially glibc and libc++ (and a lot of others ...)

OK, that's clearer - you said "after a compiler update", rather than
"after a system update" or "after a library update".

>
> My situation is as follows: I have two Linux machines, an old one and a
> new one, both with gcc 4.9.2, but with a different bunch of libs. The
> old one compiles fine, the new one doesn't know malloc in cstdlib. Sure
> I have glibc on this machine, sure I have also all the glibc-headers,
> sure malloc is an existing, documented and well known function. I never
> changed anything in these files or in the permissions, all is standard,
> but cstdlib doesn't know malloc.
>
> OK, for me it's a hint that noone says, yes, that's right, they changed
> something last sunday in glibc, malloc is banned for ever, or so.
>
> T.M.
>

Can you do a quick comparison of the headers between the machines, to
see if something has dramatically changed there? It won't be the
libraries that have changed, as you haven't got that far (they only
affect the linking stage).

Scott Lurndal

unread,
Feb 18, 2015, 9:17:21 AM2/18/15
to
Compile on both systems using -E and compare the resulting output. That
should tell you where, exactly, the malloc is defined (and the path to get
there) in the working example; which should lead you to the difference.

IIRC, some versions of gcc used to implicitly declare malloc.

Robert Wessel

unread,
Feb 19, 2015, 12:33:23 PM2/19/15
to
Could you be seeing a namespace problem? While cstdlib mostly
includes stdlin.h, it does put most items into the std: namespace.
Perhaps the headers got tightened up recently to not put those
functions in both std: and the global namespace?
0 new messages