xcode 致命错误:找不到“endian.h”文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27073837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:14:31  来源:igfitidea点击:

fatal error: 'endian.h' file not found

cxcodemacos

提问by user93097373

Trying to compile C program, every time I run makeor gmakeas recommended I get this error.

尝试编译 C 程序时,每次运行makegmake按照建议我都会收到此错误。

$ 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/machinebut 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

根据网上的一些表格建议检查此位置的文件, ~/usr/include/machine但没有说明如果找到该怎么办!没有其他帮助。然后,我找到了这个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 :(!

PS:我是新手,我不知道上面这个链接在说什么:(!

回答by Samuel Peter

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

在 OSX 和 iOS 上,您可以通过这种方式包含 endian.h:

#include <machine/endian.h>

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

但请注意,这将在 Android 或 Linux 上失败,因为他们期望#include <endian.h>.

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

您还可以包含 sys/types.h,它将在 iOS/OSX 和 Android/Linux 上包含正确的 endian.h:

#include <sys/types.h>

回答by blld

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

你必须告诉 c 编译器它可以在哪里找到这个文件:

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

export CFLAGS="$CFLAGS -I~/usr/include/machine"然后运行make

Alternatively you can edit the file Makefileto add the -I~/usr/include/machinepart where necessary.

或者,您可以编辑文件Makefile-I~/usr/include/machine在必要时添加零件。