在mac osx上找不到endian.h

时间:2013-12-28 09:37:35

标签: c macos header-files

当我在我的mac上编译一些C代码时遇到了一些麻烦,这给了我这个错误:

致命错误:'endian.h'       找不到文件

我做了一些关于这个问题的谷歌搜索。似乎mac os x没有像“endian.h”这样的头文件,我们必须手动创建这个文件。

然后,我发现这个http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Endian.h可能是我要找的文件,但不确定。

但更多麻烦即将来临......我应该把这个文件放在哪里?

文件/ usr / include不存在。

这些是我/ usr目录中的文件夹:

X11 bin libexec共享 X11R6 lib sbin独立

有没有人可以帮我查一下我发现的endian.h文件的正确性,并告诉我把这个文件放在我的mac中的哪个位置?

5 个答案:

答案 0 :(得分:15)

OS X上的Xcode默认情况下不安装命令行工具。取决于你的 你需要的Xcode和OS X版本

  • 从Xcode首选项 - >下载窗口或
  • 安装命令行工具
  • 从终端命令行执行xcode-select --install

这也将安装“/ usr / include”文件,包括“/usr/include/machine/endian.h”。

对于 Xcode 10 及更高版本,请参阅Camille G.'s answer

答案 1 :(得分:6)

从Apple上下载并安装用于XCode 10.X的命令行工具(macOS 10.X)https://developer.apple.com/download/more/

自MacOS 10.14起,它将不再创建 / usr / include 文件夹。 这需要安装一个额外的软件包,您可以在安装命令行工具后在计算机上找到该软件包:

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

答案 2 :(得分:4)

我刚使用[Thu Sep 28 17:14:23.932811 2017] [:error] [pid 6673] [client 000.000.000.000:56806] user xxxxx authentication failure, referer: http://jayjezz.com/administrator/index.php 而不是<machine/endian.h>

有效。

如第一条评论所述,<endian.h>位于endian.h文件夹中。

答案 3 :(得分:2)

实际上,您应该导入“Endian.h” 检查你的磁盘管理器,也许你的磁盘是区分大小写的

答案 4 :(得分:1)

我今天有一个类似的问题。为了解决该问题,我确实在endian.h处创建了一个名为/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__ */

要旨是

  

https://gist.github.com/dendisuhubdy/19482135d26da86cdcf442b3724e0728

或仅将指向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