gea*_*sos 20 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中的位置吗?
Mar*_*n R 17
OS X上的Xcode默认不安装命令行工具.根据您的Xcode和OS X版本,您必须这样做
xcode-select --install从终端命令行执行.这也将安装"/ usr/include"文件,包括"/usr/include/machine/endian.h".
对于Xcode 10及更高版本,请参阅Camille G.的回答.
从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
我今天遇到了类似的问题。为了解决这个问题,我做了一个名为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__ */
Run Code Online (Sandbox Code Playgroud)
要点是
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24728 次 |
| 最近记录: |