RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

malloc.h not found on OS X

Open josephnoir opened this issue 11 years ago • 12 comments

Using the native port on OS X with clang I get this error when using pthread:

/Users/noir/Desktop/RIOT/sys/posix/pthread/pthread.c:22:10: fatal error: 'malloc.h' file not found
#include <malloc.h>
         ^
1 error generated.

josephnoir avatar Jan 27 '15 17:01 josephnoir

There is one in the tree at ./sys/oneway-malloc/include/malloc.h

The "real" posix malloc is defined in #include <stdlib.h>

jnohlgard avatar Jan 28 '15 06:01 jnohlgard

@josephnoir is this fixed now? Can we close this issue?

PeterKietzmann avatar Mar 04 '15 11:03 PeterKietzmann

No, this is not fixed.

josephnoir avatar Mar 06 '15 12:03 josephnoir

Did you test @gebart's proposal? Are you willing to fix it :-)?

PeterKietzmann avatar Mar 06 '15 13:03 PeterKietzmann

Is there a reason to use malloc.h over stdlib.h. It's my understanding that stdlib.h is more portable so it should be fine to change all #include <malloc.h> to #include <stdlib.h> or will this cause issues somewhere?

jhollister avatar Mar 07 '15 08:03 jhollister

Unconditionally including stdlib.h leads to conflicts with native on Linux:

/home/lo/RIOT/sys/posix/pthread/include/pthread_threading_attr.h:34:3: error: conflicting types for ‘pthread_attr_t’

LudwigKnuepfer avatar Mar 07 '15 09:03 LudwigKnuepfer

@LudwigOrtmann is that an error in either implementation or are we just not compatible with Linux?

jnohlgard avatar Mar 07 '15 16:03 jnohlgard

I was able to use an if define to get around the malloc.h issue in OSX but I still couldn't compile because of #2360

jhollister avatar Mar 07 '15 18:03 jhollister

@jhollister care to open a PR with your fix?

LudwigKnuepfer avatar Mar 08 '15 18:03 LudwigKnuepfer

I don't have much experience with compatibility stuff like this. Is it correct to do something like:

#if defined(__MACH__)
#include <stdlib.h>
#else 
#include <malloc.h>

and should I do this for every occurrence of #include <malloc.h>?

jhollister avatar Mar 12 '15 21:03 jhollister

You could also try to mess around with conditionally adding a local malloc.h for OSX (probably by extending the include path).

LudwigKnuepfer avatar Mar 12 '15 21:03 LudwigKnuepfer

#2590 has been merged

LudwigKnuepfer avatar Mar 21 '15 12:03 LudwigKnuepfer