Solution to "Missing malloc.h" problem in MacOSX

Use this forum to discuss the book: Using OpenMP - Portable Shared Memory Parallel Programming, by Barbara Chapman, Gabriele Jost and Ruud van der Pas Read the http://openmp.org/forum/viewtopic.php?f=8&t=465 for book info and to download the examples. Post your feedback about the book and examples to this forum
Post Reply
james.lin

Solution to "Missing malloc.h" problem in MacOSX

Post by james.lin »

Hi Ruud,

Problem: I have compiled the examples source in MacOX 10.5.5 with Intel C plus plus compiler 10.1, and met "Missing headfile malloc.h" problem in Chapter6.

Reason: someone said, Apple put malloc.h in different place :( . Actually it was expecting it to be in the /usr/include directory, when it was actually in the /usr/include/malloc directory.

Possible Solution: edit the source code, 1)remove or comment #include <malloc.h> or 2) change it to #include <malloc/malloc.h>

hope this help. :)

James (Xinhua) Lin

ruud

Re: Solution to "Missing malloc.h" problem in MacOSX

Post by ruud »

Hi Xinhua,

Thank you very much for trying out these examples on Mac OS X and for the feedback!

This is very good to know and I hope it benefits others.

It is unfortunate this file is not in /usr/include. I'm not sure leaving out the
#include <malloc.h> line is going to work on other systems though and am
concerned it might break things.

Maybe this can be solved by using an option on the compiler to also let it search
in non-default include directories.

Kind regards, Ruud

james.lin

Re: Solution to "Missing malloc.h" problem in MacOSX

Post by james.lin »

Hi Ruud,

Thanks for your reply. I understand your concern about portability. So how about adding a Marco, such as

Code: Select all

#ifndef __APPLE__
#include <malloc.h>
#endif
or one more readable:

Code: Select all

#ifdef __APPLE__
#   include <malloc/malloc.h>
#else 
#   include <malloc.h>	
#endif
into the source file?
Last edited by james.lin on Tue May 19, 2009 12:50 am, edited 1 time in total.

nathanweeks
Posts: 41
Joined: Sun May 17, 2009 6:19 am
Location: Iowa State University
Contact:

Re: Solution to "Missing malloc.h" problem in MacOSX

Post by nathanweeks »

Per the C99 standard, malloc() is declared in stdlib.h.

--
Nathan Weeks
--
Nathan Weeks
Iowa State University HPC Group
http://weeks.public.iastate.edu/

Post Reply