【问题标题】:Visual C++ compiler, errors compiling stdlib.hVisual C++ 编译器,编译 stdlib.h 时出错
【发布时间】:2012-01-24 21:28:38
【问题描述】:

我正在尝试编译一个需要 cmath 中包含的函数的文件。我不相信我的代码本身是导致此错误的错误,我怀疑配置(即使所有非包含代码都已注释,它仍然存在),但不知道出了什么问题。我正在 64 位 Windows 主机上编译。除了添加 masm 构建配置之外,我认为我没有将任何编译设置更改为非默认设置,并且在禁用 masm 并将目标配置设置为 32 位后问题仍然存在。这是我生成的输出:

1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(468): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(468): error C2447: '{' : missing function header (old-style formal list?)
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(472): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(472): error C2447: '{' : missing function header (old-style formal list?)

任何帮助将不胜感激。

编辑:

我找到了麻烦的线路。与我的预期相反,代码中确实出现了错误,并且是从先前版本继承的一行的错误:

#define abs(a) ((a)<0? -(a):(a))

对我的问题负责。

【问题讨论】:

  • 请显示包含代码的位置。
  • 不仅如此,请向我们展示一个展示问题的小型完整源文件。

标签: c++ visual-studio-2010 visual-c++


【解决方案1】:

下一次,#include 系统标头位于您自己的任何代码之前。这样一来,您的宏就不会与系统标头混淆并导致您误入歧途。

【讨论】:

  • 并注意windows.h 和 C++ 标准库之间的交互。始终使用#define NOMINMAX 保护自己。
猜你喜欢
  • 2013-08-20
  • 1970-01-01
  • 2012-01-28
  • 2018-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
相关资源
最近更新 更多