我在使用 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设置中禁用它,它可以正常编译:
关于c - 'send' 的 OS X 冲突类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29477856/