10

Trying to compile C program, every time I run make or gmake as recommended I get this error.

$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src all
gcc -g -W -Wall -O3 -D_FILE_OFFSET_BITS=64 -D_REVISION=0  -Iinclude   -c -o osdep/radiotap/radiotap.o osdep/radiotap/radiotap.c
In file included from osdep/radiotap/radiotap.c:17:
osdep/radiotap/platform.h:6:10: fatal error: 'endian.h' file not found
#include <endian.h>
         ^
1 error generated.
make[1]: *** [osdep/radiotap/radiotap.o] Error 1
make: *** [all] Error 2


$ gmake
gmake -C src all
gmake[1]: Entering directory '/Users/silent/Desktop/aircr-1.2-rc1/src'
gcc -g -W -Wall -O3 -D_FILE_OFFSET_BITS=64 -D_REVISION=0  -Iinclude   -c -o osdep/radiotap/radiotap.o osdep/radiotap/radiotap.c
In file included from osdep/radiotap/radiotap.c:17:
osdep/radiotap/platform.h:6:10: fatal error: 'endian.h' file not found
#include <endian.h>
         ^
1 error generated.
<builtin>: recipe for target 'osdep/radiotap/radiotap.o' failed
gmake[1]: *** [osdep/radiotap/radiotap.o] Error 1
gmake[1]: Leaving directory '/Users/silent/Desktop/aircr-1.2-rc1/src'
Makefile:25: recipe for target 'all' failed
gmake: *** [all] Error 2

According to some forms online recommended to check the file in this location ~/usr/include/machine but doesn't say what to do if found or not! nothing else was helpful. Then, I found this http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Endian.h

silent:~/usr/include/machine
$ ls
_limits.h      _types.h       fasttrap_isa.h profile.h      vmparam.h
_mcontext.h    byte_order.h   limits.h       signal.h
_param.h       `endian.h`       param.h        types.h

As you can the file I am getting the error for is already existed! Any help would be appreciated. Thank you.

PS: I am newbie, I don't know what is this link above talking about :(!

user93097373
  • 187
  • 1
  • 3
  • 11
  • 2
    Have you tried to copy and paste endian.h to the /usr/include? This answer is here http://stackoverflow.com/questions/20813028/endian-h-not-found-on-mac-osx – amrx Nov 22 '14 at 04:21
  • This is where I get to that link, but I have not tried that, will do now and see what happens. – user93097373 Nov 22 '14 at 06:40
  • @user3097840, I Get more errors for missing linking so I put it back, the error resolves with reboot. Now its getting `Undefined symbols for architecture x86_64:` – user93097373 Nov 22 '14 at 09:18
  • Adding the definitions [here](http://debugjournal.tumblr.com/post/99661010362/missing-byteswap-h-and-endian-h-on-mac-os-x) and adding -D_DARWIN_SOURCE to CFLAGS solved it for me. – Moshe Jul 14 '15 at 15:29

2 Answers2

10

On OSX and iOS, you can include endian.h this way:

#include <machine/endian.h>

But note that this will fail on Android or Linux because they expect #include <endian.h>.

You can also include sys/types.h, which will include the right endian.h both on iOS/OSX and Android/Linux:

#include <sys/types.h>
Samuel Peter
  • 4,136
  • 2
  • 34
  • 42
2

You have to tell the c compiler where it can find this file:

export CFLAGS="$CFLAGS -I~/usr/include/machine" then run make.

Alternatively you can edit the file Makefile to add the -I~/usr/include/machine part where necessary.

blld
  • 1,030
  • 10
  • 19