- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在编译 C 程序时在预处理步骤中遇到错误。
奇怪的是,我可以运行预处理而没有错误或警告:
gcc -I/usr/local/libpng-1.6.24/include -Wall -std=c99 lines.c -E -o lines
但是使用下面的表格给我错误:
cpp -I/usr/local/libpng-1.6.24/include -std=c99 lines.c -o lines
我假设 cpp 作为 gcc 的一部分运行,这使得它更奇怪。
有关信息,请参阅下面我收到的错误 - 只有其中一个,我有很多相同类型的错误:
In file included from lines.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/stdio.h:65:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/Availability.h:172:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/AvailabilityInternal.h:15284:10: error:
unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11
不用说,出错的文件是苹果标准文件。我还必须说,让所有终止 #endif 匹配他们的 #if 指令对我来说似乎没问题
知道这里会发生什么吗?或者追踪错误的方法?
PS 顺便说一下,我在 OSX 中使用 Apple 提供的标准开发工具运行它。
--
添加附加信息作为对某些评论的回应:
lines.c源码https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s096-introduction-to-c-and-c-january-iap-2013/final-project/starter-kit/lines.c并了解有关源代码使用位置的更多上下文,您可能希望在此处查看 https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s096-introduction-to-c-and-c-january-iap-2013/final-project/starter-kit/
如果我在没有选项 -E 的情况下运行 gcc 实际上,由于我的文件夹结构,我会遇到链接问题,但下面的命令将正常工作 - 但我认为此信息与问题无关,因为我想比较like for like 选项 -E 在预处理后停止,cpp 只做预处理:
gcc -I/usr/local/libpng-1.6.24/include -L/usr/local/libpng-1.6.24/lib -Wall -std=c99 lines.c -lpng -o lines
--
我已将 Xcode 从 7.3 升级到 8.2.1,命令行工具从 Command_Line_Tools_OS_X_10.11_for_Xcode_7.3 升级到 Command_Line_Tools_macOS_10.12_for_Xcode_8.2,gcc 继续工作,cpp 仍然触发错误。但是这次错误发生了一点变化。见下文
In file included from lines.c:1:
In file included from /usr/include/stdio.h:65:
In file included from /usr/include/Availability.h:184:
/usr/include/AvailabilityInternal.h:20265:10: error: #else without #if
#else
/usr/include/AvailabilityInternal.h:20832:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11_4
最佳答案
如评论中所述,我可以在装有 XCode 8 的 macOS Sierra 10.12.3 机器上重现您的问题,得到(至少)20 个错误,因此它在 20 日停止。
源文件:
#include <stdio.h>
int main(void) { puts("Hi"); return 0; }
命令行和错误输出:
$ /usr/bin/cpp -v min.c -o min.c.out >/dev/null
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name min.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -fdebug-compilation-dir /Users/jleffler/soq -ferror-limit 19 -fmessage-length 110 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -traditional-cpp -o - -x c min.c
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.4.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
In file included from min.c:1:
In file included from /usr/include/stdio.h:65:
In file included from /usr/include/Availability.h:184:
/usr/include/AvailabilityInternal.h:20265:10: error: #else without #if
#else
^
/usr/include/AvailabilityInternal.h:20832:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11_4
^
/usr/include/AvailabilityInternal.h:20765:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11_3
^
/usr/include/AvailabilityInternal.h:20702:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11_2
^
/usr/include/AvailabilityInternal.h:20643:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11
^
/usr/include/AvailabilityInternal.h:20588:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10_3
^
/usr/include/AvailabilityInternal.h:20537:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10_2
^
/usr/include/AvailabilityInternal.h:20490:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10
^
/usr/include/AvailabilityInternal.h:20447:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_9
^
/usr/include/AvailabilityInternal.h:20408:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8
^
/usr/include/AvailabilityInternal.h:20373:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_7
^
/usr/include/AvailabilityInternal.h:20342:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6
^
/usr/include/AvailabilityInternal.h:20315:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_5
^
/usr/include/AvailabilityInternal.h:20292:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_4
^
/usr/include/AvailabilityInternal.h:20273:10: error: unterminated conditional directive
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_3
^
In file included from min.c:1:
In file included from /usr/include/stdio.h:65:
/usr/include/Availability.h:233:2: error: #else without #if
#else
^
/usr/include/Availability.h:236:2: error: #endif without #if
#endif
^
/usr/include/Availability.h:272:2: error: #endif without #if
#endif
^
/usr/include/Availability.h:299:2: error: #endif without #if
#endif
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
$
请注意,我使用的唯一选项是 -v
(在开始时产生详细的输出)和 -o min.c.out
(结束 -在冗长的输出中充满了 -o -
;它按照它想要的方式而不是按照我告诉它的方式去做——排名不服从,真的)。因此,必须将标准输出重定向到 /dev/null
以避免看到所有输出。
如果我将 /usr/bin/cpp
替换为 /usr/bin/gcc
(该路径对我来说是必需的,因为 gcc
是/opt/gcc/v6.2.0/bin/gcc
,又名 GCC 6.2.0),我添加了 -E
选项,它工作正常:
$ /usr/bin/gcc -E -v min.c -o min.c.out
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name min.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -fdebug-compilation-dir /Users/jleffler/soq -ferror-limit 19 -fmessage-length 110 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o min.c.out -x c min.c
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.4.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
$ wc -l min.c.out
456 min.c.out
$
这强烈暗示了 /usr/bin/cpp
程序中的某种问题以及它驱动其余编译工具链的方式,但我还没有确定关键的区别在命令行中。
它还暗示了一个解决方案——不要单独使用 cpp
。正如我在评论中指出的那样,2017 年 1 月有一个问题 — How to get XCode 8 C preprocessor to ignore //
comments in #define
s? 也指出了独立 cpp
中的一个问题。
如果您必须有可用的 cpp
,请安装您自己的。例如,您可以在某个位置(例如 /opt/gcc/v6.0)安装 GCC 6.3.0(我在这台机器上很懒;我的另一台机器已经在运行 6.3.0,而不是 6.2.0)。 3.0/bin/cpp
),然后在键入 cpp
时安排运行它而不是 /usr/bin/cpp
— 调整 PATH
,或将符号链接(symbolic link)或脚本放在 /usr/local/bin
或 $HOME/bin
等目录中,该目录出现在 PATH
在 /usr/bin
之前,或在 makefile
中指定正确的 PATH,或任何需要的内容。
如果您需要有关在 Mac 上构建 GCC 的指南,请考虑:
关于c - 预处理 C 代码时出现未终止的无条件指令错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42031921/
我正在尝试在现有指令的基础上构建一个新指令,但我在我的过程中停止了。加载页面时,我面临以下错误: Multiple directives [directive#1, directive#2] aski
我是 angularjs 世界的新手,我只需要在数字类型的输入中输入从 1 到 10 的数字。不使用 HTML5 的 min 和 max 属性 我在 Jquery 中找到了一个示例,能否帮我将其转换为
我想使用 ionic与 Material 设计。我被困在使用带有自定义 CSS 的 ionic 指令和 angular-material 之间。 我读过使用 ionic 指令我们得到了很多高效的特性,
我创建了以下代码: var node = document.getElementById('TreeList'); var keys = Object.keys(model[0]); var trac
在 AngularJs 中没有提供 ng-enabled 指令。是否有任何适当的理由不在框架中提供该指令,因为当您可以使用 ng- 时,我们同时拥有 ng-show 和 ng-hide隐藏来实现我们的
我最近制作的程序有问题。基本上,它是 John Conway 人生游戏的简单版本,但它运行不正常。问题出在读取单元格及其邻居的状态并决定该单元格的 future 状态的代码中。这是代码的一部分(有点长
Dockerfile reference关于 FROM 指令的内容如下: FROM can appear multiple times within a single Dockerfile in or
我一直在尝试理解指令中孤立作用域和继承作用域之间的区别。这是我准备让自己理解的一个例子: HTML Inside isolated scope directive: {{m
知道如何从指令内部访问属性值吗? angular.module('portal.directives', []) .directive('languageFlag', ['$r
我正在通过将 c 程序与其等价的汇编程序进行比较来学习汇编。 这是代码。 .file "ex3.c" .section .rodata .LC0: .string "I am %d
我正在尝试写一个 Jenkinsfile并行执行一系列步骤。目标是拥有两个 agents (又名。 nodes )。一个应该进行 Windows 构建,另一个应该进行 linux 构建。但是,我不希望
我想知道为什么指令 FYL2XP1在 x86 架构上精确计算数学公式 y · log2(x + 1)。 这个公式有什么特别之处? 最佳答案 y操作数通常是编译时常量,暂时忘记 x + 1 . 自 lo
这个问题已经有答案了: Parameterize an SQL IN clause (41 个回答) 已关闭 8 年前。 第一个声明: Select GroupMember FROM Group 结果
我从 this question fork 并编辑了一个 plunker 我想做的是在数据加载后更新/填充 SELECT 元素(组合框),但有些事情不对劲。我检索数据,它位于 SELECT 元素的范围
我想创建一个简单的 markdown 指令,它接受元素中的一些内容,解析它并用 html 替换它。 所以这样: #Heading 或这个(其中 $scope.heading = '#Heading';
我对 Ansible 还很陌生,对于我对 local_action 指令的理解有一个简单的问题。 这是否意味着该命令完全在本地执行?假设你有这样的东西: local_action: command w
我有以下 HTML: ... ... 以及以下指令: myApp.directive('specialInput', ['$timeout', function($timeout)
如何在 .htaccess 中创建 Apache 指令强制文件 .mp4和 .pdf去下载?目前它们出现在浏览器窗口中。相反,我希望出现一个下载文件对话框。 最佳答案 将以下内容添加到 .htacce
我的问题是关于 C 中的 fork() 指令。我有以下程序: void main(){ int result, status; result = fork(); if(result=
我想要一个类似于 ng-model 的属性指令。我只想另外将一个输入字段值绑定(bind)到一个范围变量(只是在一个方向输入字段 ->范围变量)。所以我刚刚尝试了这个指令,但无论如何我都无法调用该指令
我是一名优秀的程序员,十分优秀!