c - 'send' 的 OS X 冲突类型

标签 c xcode macos clang

我在使用 Xcode 6.2 在 OS X 10.10 上编译代码时遇到了一些问题。

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)

Target: x86_64-apple-darwin14.1.0

我的程序很简单。头文件header.h:

int send();

我在 main.c 中包含了这个 header :

#include <stdio.h>
#include "header.h"

int main(int argc, const char * argv[]) {
    return 0;
}

当我尝试编译它时,出现以下错误:

.../header.h:12:5: Conflicting types for 'send' .../main.c:2:10: In file included from .../main.c:2: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/sys/socket.h:574:9: Previous declaration is here

ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);

为什么我在不包含 socket.h 的情况下出现此错误?我知道解决方案可以是重命名 send 函数,但我把我的牌放在 table 上了,这是我的作业,我必须只在 Linux 上用上面的声明来写它。但我想在 Mac 上编译它。我也可以创建一些宏来检查操作系统并仅在 OS X 上重命名我的函数。问题是我稍后会得到一些静态库,这个解决方案将不起作用。有什么建议么?也许我有一些错误的编译选项或 Xcode 设置?请帮忙

最佳答案

命令行上的 Clang 有效:
clang main.c

问题是 xcode 的 ModuleCache。这似乎透明地为您包含了很多东西 :D 它将以下标志传递给 clang:
-fmodules -fmodules-cache-path=/Users/dpich/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600

如果您在build设置中禁用它,它可以正常编译:
enter image description here

关于c - 'send' 的 OS X 冲突类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29477856/

相关文章:

java - 从 native pthread 调用 Java 方法时出现 SIGSEGV

c - 了解并行线程执行

c - 在 GTK 中为工具栏按钮设置不敏感状态图标

ios - 什么时候在 Objective-C 中使用 self?

xcode - 如何设置 NSSegmentedControl 的外观以匹配 Xcode 的外观?

python - Sublime Text Python 构建和打开终端需要很长时间

macos - OSX - 为 Tesseract 4.0 编译训练工具 - 未找到 pango 库

将定义从 C 转换为 Delphi

iphone - 从文档文件 iOS 中检索数据

ruby - 在 mac 上安装 mechanize 时出现错误