每次我尝试使用 `clang -Weverything` 进行编译时,都会收到警告“包含位置 '/usr/local/include' 对于交叉编译来说是不安全的”

2024-01-17

如果这个问题不清楚,我很抱歉,我什至很难开始调试这个问题。我在 macOS 上,现在每次使用以下命令编译 C 程序时都会收到以下错误/警告clang with -Weverything and -Werror flags:

error: include location '/usr/local/include' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]

最初我认为这是与我的代码相关的问题,但我发现现在我尝试编译的每个程序都会出现此错误。尽管总是使用这些标志进行编译,但我以前从未遇到过此错误,并且因为现在每个程序都会发生此错误,所以我怀疑它是我的编译器或系统更改的。我能想到最近发生的唯一变化是我在 VirtualBox 上使用 Lubuntu VM 创建了一些共享文件夹并更新了 Xcode。

我可以编译程序而无需-Weverything标志,它似乎按预期工作,但我想解决实际问题以继续使用-Weverything。正如其他人以及该线程所提到的here https://stackoverflow.com/questions/14181789/how-to-use-clang-with-std-c11-weverything-werror/14185534#14185534, using -Weverything -Werror在现实生活中是过度的,但是,我主要将其用作学习工具,我想了解为什么即使对于像这样的基本程序也会出现这个问题helloworld.c(见下文)。

我遇到过一个讨论here https://stackoverflow.com/questions/37799950/apache2-build-fails-in-yocto-usr-local-include-is-unsafe-for-cross-compilat,但答案引用了configure.ac我不熟悉并且不知道如何使用的文件。

如果我可以提供更多信息来帮助调试此问题,请告诉我。

作为示例,以下是结果cc -Weverything -Werror -v helloworld.c:

Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.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.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name helloworld.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Weverything -Werror -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdebug-compilation-dir /Users/Projects/helloworld -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/mn/v00y5wf55qjf76r4q9rvxq1c0000gn/T/helloworld-89fdc3.o -x c helloworld.c
clang -cc1 version 12.0.0 (clang-1200.0.32.2) default target x86_64-apple-darwin19.6.0
error: include location '/usr/local/include' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
1 error generated.

您有两种选择来消除此警告。

  1. 忽略此警告-Wno-poison-system-directories option.

请注意,前缀为-Wno-适用于所有警告。

完整命令:

cc -Weverything -Wno-poison-system-directories -Werror helloworld.c
  1. 使用以下命令设置逻辑系统根-isysroot option.

完整命令(如果安装了开发人员命令行工具):

cc -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Weverything -Werror helloworld.c

完整命令(使用 Xcode 内部的 SDK):

cc -isysroot "$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" -Weverything -Werror helloworld.c
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

每次我尝试使用 `clang -Weverything` 进行编译时,都会收到警告“包含位置 '/usr/local/include' 对于交叉编译来说是不安全的” 的相关文章

  • 哪些 iomanip 操纵器具有“粘性”?

    我最近在创建一个stringstream由于我错误地假设std setw 会影响每次插入的字符串流 直到我明确更改它 然而 插入后它总是被取消设置 With timestruct with value of Oct 7 9 04 AM st
  • 在静态断言和运行时错误之间自动选择

    我有一个执行除法并检查对齐的宏 define BYTES TO WORDS x CHECK ALIGNMENT x 2 x 2 我想实施CHECK ALIGNMENT作为一个总是返回 1 的宏 并且如果满足以下条件则触发错误x不除以 2 宏
  • 如何在函数中将结构成员作为指针传递?

    问题是我有一个结构是另一个 主要 结构的成员 我编写了一个函数来清除第一个结构 它需要一个指向结构的指针 我想使用该函数来清除主要结构内的结构 但我不确切知道哪种方法是正确的 为了更好地解释它 这里有一些代码 我有一个结构 定义为 type
  • 如何使用 saxon 将文档类型参数传递给 xslt?

    对于发送原子数据类型将使用类似 transformer SetParameter new QName customXml new XdmAtomicValue true 如何将 XML Node 作为参数从 C 传递给 XSLT 你能帮我么
  • C# 动态 Linq 变量Where 子句

    我正在按照 Scott Gu 的文章创建动态 LINQhttp weblogs asp net scottgu archive 2008 01 07 dynamic linq part 1 using the linq dynamic qu
  • 模拟 EF core dbcontext 和 dbset

    我正在使用 ASP NET Core 2 2 EF Core 和 MOQ 当我运行测试时 我收到此错误 消息 System NotSupportedException 非虚拟 可在 VB 中重写 成员上的设置无效 x gt x Movies
  • 将 gcov 与 CMake/CDash 结合使用的详细指南?

    我在我的项目中使用 CMake 并设置了 cdash 服务器以进行连续 夜间构建 一切运行良好 通过设置 crontab 我们可以将每小时 每晚的构建 测试结果自动上传到我们的 cdash 服务器 我的下一步是将测试覆盖率报告添加到构建中
  • string.empty 和 string[0] == '\0' 之间的区别

    假设我们有一个字符串 std string str some value is assigned 有什么区别str empty and str 0 0 C 11 及更高版本 string variable 0 如果字符串为空 则需要返回空字
  • 混合 VS2012 平台工具集

    我们正在从 VS2005 切换到 VS2012 update 2 我们正在构建大量 主要是控制台 本机 C 无 MFC ATL 可执行文件 它们使用几个常见的静态链接库 这些可执行文件主要在 Win7 计算机上运行 但有些也部署在较旧的 X
  • 如何解决素数函数的大O表示法?

    我正在尝试理解 Big O 表示法 很抱歉 如果我问的问题太明显了 但我似乎无法理解这一点 我有以下 C 代码函数 我正在尝试为其计算 Big O 表示法 for i 2 i lt 100 i for j 2 j lt i j j if i
  • 如何从c++调用python

    我是Python新手 我尝试像这样从 C 调用 python 脚本 在 Raspberry Pi 中 std string pythonCommand python Callee py a b int res system pythonCo
  • 如何检查是否发生溢出? [复制]

    这个问题在这里已经有答案了 可能的重复 检测 C C 中整数溢出的最佳方法 https stackoverflow com questions 199333 best way to detect integer overflow in c
  • 在 C# 4.0 中,是否可以从泛型类型参数派生类?

    我一直在尝试这个 但我似乎无法弄清楚 我想做这个 public abstract class SingletonType
  • 为什么 C# 编译的正则表达式比等效的字符串方法更快?

    每次我必须对字符串执行简单的包含或替换操作 其中我正在搜索的术语是固定值 时 我发现如果我获取示例输入并对其进行一些分析 则使用编译的正则表达式是几乎 总是比使用 String 类中的等效方法更快 我尝试过比较多种方法 hs是要搜索的 干草
  • CS0246 找不到类型或命名空间名称“ErrorViewModel”(您是否缺少 using 指令或程序集引用?)

    我收到 CS0246 错误代码 我正在做一个 MVC net core 项目 我正在将 Razor 合并到我的 C 代码中 我在进行构建时收到此错误 我在最后一行收到错误 有人能帮我解决这个问题吗 global Microsoft AspN
  • System.Drawing.Icon 构造函数抛出“操作成功完成”异常

    在 Windows XP 计算机上 以下代码抛出 System ComponentModel Win32Exception 并显示消息 操作成功完成 System Drawing Icon icon new System Drawing I
  • g++4.9 不支持 std::align

    在学习对齐问题等时 我意识到我的 g 4 9 macports OS X 实现不支持std align 如果我尝试编译 使用 std c 11 此示例代码来自http www cplusplus com reference memory a
  • 为 C++ 类播种 rand()

    我正在开发一个 C 类 它使用rand 在构造函数中 我真的希望这个班级在几乎所有方面都能照顾好自己 但我不知道在哪里播种rand 如果我播种rand 在构造函数中 每次构造我的对象类型的新实例时都会对其进行播种 因此 如果我按顺序创建 3
  • Python 中的 C 指针算术

    我正在尝试将一个简单的 C 程序转换为 Python 但由于我对 C 和 Python 都一无所知 这对我来说很困难 我被 C 指针困住了 有一个函数采用 unsigned long int 指针并将其值添加到 while 循环中的某些变量
  • 可选参数代码在 .NET 3.5 中编译。为什么?

    这段代码在 VS 2010 的框架 3 5 项目中编译正常 我三次检查过 public LoggingClient string uri net msmq localhost logging 为什么 我在 C 4 规范中没有看到任何内容 文

随机推荐