如何禁用“curses.h”头文件(Xcode 6.3 OSX Yosemite中的“stdio.h”的一部分)以避免冲突的函数声明

我正在尝试在Xcode中构建一个项目,但是我得到了错误Implicit declaration of function 'clear' is invalid in C99 Conflicting types for 'clear' Implicit declaration of function 'clear' is invalid in C99

这是代码:

 //main.c #include  #include "tree.h" int main(){ clear(); // Implicit declaration of function 'clear' is invalid in C99 return 0; } //tree.c #include  #include "tree.h" void clear(){ ///Conflicting types for 'clear' printf("Command clear.\n"); } //tree.h #include  void clear(); ///Conflicting types for 'clear' 

为什么我会收到这些错误和警告? 我试图在StackOverflow上搜索解决方案,但所有相关的答案都是关于没有某种#include的情况。

‘clear’不是C中的关键字,所以不是他的情况,是吗?
(来源: http : //aboutc.weebly.com/keywords.html )

相关主题(尽管它们实际上是相关的,但不回答我的问题):

  • 函数’sum’的隐式声明在C99中无效
  • C99中隐含的函数声明无效

谢谢你的帮助。


UPDATE!

事实certificate,将clear funtcion的名称更改为cleark函数解决了这个问题。 然而,它对我来说没有任何意义。


更新2!

我的项目基于OS 10.10上Xcode 6.3的command line tool模板。 因为Xcode已经为项目的编译器自动添加了一些库和标志。 这里最重要的是添加了curses.h头文件,这个头文件已经包含了clear()函数

以下是Conflicting types for 'clear'错误日志的Conflicting types for 'clear'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/curses.h:541:28: Previous declaration is here

我试图手动从编译器的标志中删除-lcurses ,但我找不到这样的设置。 有没有其他方法来构建项目? (总而言之,我的目标是在项目扩展时能够使用Xcode的调试器)


更新3! 根据Paul Griffiths在下面的评论中发现和发表的内容,问题如下:

我确实可以用Xcode 6.3.1复制这个问题,只提供代码。 出于某种原因,stdio.h似乎包括curses.h (即如果你不包括stdio.h,这个问题就会消失),而且我还没有很快找到办法阻止它这样做。 这似乎是有问题的,因为标准头文件不应该将随机符号导入全局命名空间,而没有简单明了的方法将其关闭。

通常我运行C预处理器来查看编译器实际解析的内容。 但是,遵循Xcode预处理器输出来检查Xcode的预处理器输出并没有实现 – 它正在将#include转换为@import 。 以下是预处理器视图向我显示的内容:

 // Preprocessed output for tree.c // Generated at 9:24:57 PM on Friday, May 1, 2015 // Using Debug configuration, x86_64 architecture for curses-vs-stdio target of curses-vs-stdio project # 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c" # 1 "" 1 # 1 "" 3 # 322 "" 3 # 1 "" 1 # 1 "" 2 # 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c" 2 # 1 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.h" 1 void clear(void); @import Darwin.C.stdio; /* clang -E: implicit import for "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/stdio.h" */ # 5 "/Users/thomas/Desktop/curses-vs-stdio/curses-vs-stdio/tree.c" 2 void clear(void) { printf("Command clear.\n"); } 

显然问题是Xcode使用模块不是stdio.h包括curses.h 。 “达尔文”模块就是问题所在。

实际上,如果我禁用模块(使用Enable Clang Modules中的提示,禁用自动链接 ),构建问题就会消失。 这是

  • 在构建设置中
  • Apple LLVM 6.1 – 语言 – 模块
  • 设置启用模块(C和Objective-C)

作为对问题的进一步暗示,稍微重新安排了示例(将原型放在include之前),我看到一条消息抱怨重载 – 但这不是C.

也许Apple会在下一个版本中解决这个问题。

你包括“trie.h”,而不是“tree.h”。

但也许那只是你在发布代码时不小心……

我打赌在某处定义了另一个名为clear()的函数。 可能在您的stdio.h版本中。