每次我尝试使用 `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' 对于交叉编译来说是不安全的” 的相关文章

随机推荐