Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

foidulus

macrumors 6502a
Original poster
Jan 15, 2007
904
1
I am currently working on a research tool at school and am wondering why in a couple of cases the C code compiles fine in Linux, but in OS X a couple of separate includes(such as sys.h, types.h etc) are necessary. After the includes the software compiles and runs fine, but I'm a bit of a C newb, so I'm not quite sure why they are necessary.

Is there actually a difference between how gcc locates header files on OS X vs. Linux? Is there any way I can get OS X to behave more like Linux?

I've just been putting in the extra includes, shouldn't hurt anything.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Is there any way I can get OS X to behave more like Linux?

I've just been putting in the extra includes, shouldn't hurt anything.

You should probably look into conditional includes, for example.

Code:
#ifdef __APPLE__
      #define <whatever.h>
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
These are header files outside of the C language specification. They are platform header files defined by various other standards such as POSIX and the Single Unix Standard. What I think you're encountering are issues with platform differences. You're actually porting Linux code to Mac OS X. Luckily though Mac OS X and Linux are close enough that all you need to do include extra header files.

If you want to the code to compile under both "out of the box", you could surround the includes with #ifdef's. Or investigate autoconf, but that's probably overkill.
 

Hansr

macrumors 6502a
Apr 1, 2007
897
1
Some older versions of gcc or specific forked builds automatically define a set of headers but I though that was removed after 3.x. Might want to use the same compiler on both machines and see how that performs.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.