本文介绍了每次我尝试使用`clang-WEverthing`进行编译时,收到警告和包含位置/usr/local/include'对于交叉编译是不安全的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,如果这个问题不清楚,我甚至正在努力开始调试这个问题。我在MacOS上,现在每次使用clang-Weverything and -Werror标志编译C程序时都会收到以下错误/警告:

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

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

我可以在没有-Weverything标志的情况下编译程序,它似乎可以按预期工作,但我想解决实际问题以继续使用-Weverything。正如其他人提到的here以及这个帖子here-Weverything -Werror在现实生活中使用过度,然而,我主要将其用作学习工具,我想了解为什么即使是像helloworld.c这样的基本程序(见下文)也会出现这个问题。

我遇到一个讨论here,但答案引用了一个我不熟悉且不确定如何使用的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选项忽略此警告。

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

完整命令:

cc -Weverything -Wno-poison-system-directories -Werror helloworld.c
  1. 使用-isysroot选项设置逻辑系统根。

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

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

这篇关于每次我尝试使用`clang-WEverthing`进行编译时,收到警告和包含位置/usr/local/include&#39;对于交叉编译是不安全的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:54