C语言 在 mac osx 上找不到 endian.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20813028/
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
endian.h not found on mac osx
提问by geasssos
I meet some trouble when I compile some C code on my mac which give me this error :
当我在我的 mac 上编译一些 C 代码时遇到了一些麻烦,这给了我这个错误:
fatal error: 'endian.h' file not found
致命错误:找不到“endian.h”文件
I did some google search about this problem.It seems like mac os x does not have header files like "endian.h", we have to create this file manually.
我对这个问题做了一些谷歌搜索。似乎 mac os x 没有像“endian.h”这样的头文件,我们必须手动创建这个文件。
Then, I found this http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Endian.hwhich might be the file I am looking for but not sure.
然后,我找到了这个http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Endian.h这可能是我正在寻找但不确定的文件。
But more troubles are coming.. where should I put this file?
但是更多的麻烦来了..我应该把这个文件放在哪里?
The file /usr/include does not exist.
文件 /usr/include 不存在。
These are the folders in my /usr directory:
这些是我的 /usr 目录中的文件夹:
X11 bin libexec share X11R6 lib sbin standalone
X11 bin libexec 共享 X11R6 lib sbin 独立
Could anyone help me to check the correctness of the endian.h file I found and tell me where to put this file in my mac please?
谁能帮我检查我找到的 endian.h 文件的正确性,并告诉我将此文件放在我的 mac 中的哪个位置?
采纳答案by Martin R
Xcode on OS X does not install the command-line tools by default. Depending on your Xcode and OS X version you have to
OS X 上的 Xcode 默认不安装命令行工具。根据您的 Xcode 和 OS X 版本,您必须
- install the command line tools from the Xcode Preferences->Downloads window, or
- execute
xcode-select --installfrom the Terminal command-line.
- 从 Xcode Preferences->Downloads 窗口安装命令行工具,或
xcode-select --install从终端命令行执行。
This will also install the "/usr/include" files, including "/usr/include/machine/endian.h".
这还将安装“/usr/include”文件,包括“/usr/include/machine/endian.h”。
For Xcode 10and later, see Camille G.'s answer.
对于Xcode 10及更高版本,请参阅Camille G. 的回答。
回答by Husen
I just used <machine/endian.h>rather than <endian.h>.
我只是使用<machine/endian.h>而不是<endian.h>.
It works.
有用。
As said in the first comment, endian.his in /usr/include/machine/folder.
正如第一条评论中所说,endian.h在/usr/include/machine/文件夹中。
回答by Camille G.
Download and install the Command Line Tools (macOS 10.X) for XCode 10.Xfrom Apple : https://developer.apple.com/download/more/
从 Apple下载并安装适用于 XCode 10.X的命令行工具 (macOS 10.X):https: //developer.apple.com/download/more/
Since MacOS 10.14 this will not create anymore the /usr/includefolder.This require the installation of an extra package that you could find on your computer after having installed the command-line tools :
从 MacOS 10.14 开始,这将不再创建/usr/include文件夹。这需要安装一个额外的软件包,您可以在安装命令行工具后在计算机上找到该软件包:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
回答by Dendi Suhubdy
I had a similar issue today. To solve the problem I did make a file named endian.hat /usr/local/include/endian.hthat contains
我今天遇到了类似的问题。为了解决这个问题,我做了一个名为endian.hat的文件,/usr/local/include/endian.h其中包含
#ifndef __FINK_ENDIANDEV_PKG_ENDIAN_H__
#define __FINK_ENDIANDEV_PKG_ENDIAN_H__ 1
/** compatibility header for endian.h
* This is a simple compatibility shim to convert
* BSD/Linux endian macros to the Mac OS X equivalents.
* It is public domain.
* */
#ifndef __APPLE__
#warning "This header file (endian.h) is MacOS X specific.\n"
#endif /* __APPLE__ */
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#endif /* __FINK_ENDIANDEV_PKG_ENDIAN_H__ */
gist is
要点是
https://gist.github.com/dendisuhubdy/19482135d26da86cdcf442b3724e0728
https://gist.github.com/dendisuhubdy/19482135d26da86cdcf442b3724e0728
or just change the the header pointing to endian.hinstead to
或者只是将指向的标题更改endian.h为
#if defined(OS_MACOSX)
#include <machine/endian.h>
#elif defined(OS_SOLARIS)
#include <sys/isa_defs.h>
#ifdef _LITTLE_ENDIAN
#define LITTLE_ENDIAN
#else
#define BIG_ENDIAN
#endif
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
defined(OS_DRAGONFLYBSD)
#include <sys/types.h>
#include <sys/endian.h>
#else
#include <endian.h>
#endif
回答by alex yuan
In fact, you should import "Endian.h" check your disk manager, maybe your disk is case sensitive
实际上,您应该导入“Endian.h”检查您的磁盘管理器,也许您的磁盘区分大小写

