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 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

Solution to "Missing malloc.h" problem in MacOSX

Postby james.lin » Thu May 14, 2009 2:55 am

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
james.lin
 
Posts: 2
Joined: Thu May 07, 2009 10:51 pm

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

Postby ruud » Sun May 17, 2009 9:44 pm

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
ruud
 
Posts: 23
Joined: Mon Nov 26, 2007 2:13 am

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

Postby james.lin » Mon May 18, 2009 1:48 am

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.
james.lin
 
Posts: 2
Joined: Thu May 07, 2009 10:51 pm

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

Postby nathanweeks » Mon May 18, 2009 4:06 am

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

--
Nathan Weeks
--
Nathan Weeks
Iowa State University HPC Group
http://weeks.public.iastate.edu/
nathanweeks
 
Posts: 41
Joined: Sun May 17, 2009 6:19 am
Location: Iowa State University


Return to Using OpenMP - The Book and Examples

Who is online

Users browsing this forum: No registered users and 4 guests