gpt4 book ai didi

c++ - clang 不应该抑制来自/usr/local/include 中头文件的警告吗?

转载 作者:太空狗 更新时间:2023-10-29 23:12:12 25 4
gpt4 key购买 nike

我正在 OSX 上构建一个使用 Boost.Log 的应用程序。当我将警告标志设置为包含 -Wextra 时,我收到有关 Boost 头文件之一中未使用参数的警告。

MWE:

#include <boost/log/trivial.hpp>

int main() {
BOOST_LOG_TRIVIAL(error) << "no log";
return 0;
}

另存为nolog.cpp,然后编译:

c++ -Wextra -DBOOST_LOG_DYN_LINK -o nolog -lboost_log-mt nolog.cpp

我看到以下错误:

In file included from nolog.cpp:1:
In file included from /usr/local/include/boost/log/trivial.hpp:23:
In file included from /usr/local/include/boost/log/sources/record_ostream.hpp:36:
In file included from /usr/local/include/boost/log/utility/formatting_ostream.hpp:30:
/usr/local/include/boost/log/detail/attachable_sstream_buf.hpp:284:67: warning: unused parameter 'n' [-Wunused-parameter]
size_type length_until_boundary(const char_type* s, size_type n, size_type max_size, mpl::true_) const
^
1 warning generated.

我原以为 /usr/local/include 中的任何内容都会被视为系统 header ,因此会抑制其警告,但显然不是。

我也尝试过添加 --system-header-prefix/usr/local/include 但这并没有什么不同。

更新

按照@KompjoeFriek 的建议,这里是带有-### 的输出:

$ c++ -Wextra -DBOOST_LOG_DYN_LINK -o nolog -lboost_log-mt --system-header-prefix /usr/local/include -### nolog.cpp
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.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.13.0" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "nolog.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-fno-strict-return" "-masm-verbose" "-munwind-tables" "-target-cpu" "penryn" "-target-linker-version" "305" "-dwarf-column-info" "-debugger-tuning=lldb" "-resource-dir" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0" "--system-header-prefix=/usr/local/include" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" "-D" "BOOST_LOG_DYN_LINK" "-I/usr/local/include" "-stdlib=libc++" "-Wextra" "-fdeprecated-macro" "-fdebug-compilation-dir" "/Users/dlindelof/Work/endor/libneurobat" "-ferror-limit" "19" "-fmessage-length" "181" "-stack-protector" "1" "-fblocks" "-fobjc-runtime=macosx-10.13.0" "-fencode-extended-block-signature" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/var/folders/gf/l78h_kjs1bg6j_p18gt05_t80000gn/T/nolog-1cdc02.o" "-x" "c++" "nolog.cpp"
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" "-demangle" "-lto_library" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib" "-no_deduplicate" "-dynamic" "-arch" "x86_64" "-macosx_version_min" "10.13.0" "-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" "-o" "nolog" "-lboost_log-mt" "/var/folders/gf/l78h_kjs1bg6j_p18gt05_t80000gn/T/nolog-1cdc02.o" "-L/usr/local/lib" "-lc++" "-lSystem" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a"

更新

运行xcode-select install后,问题消失了。不知道。为什么。

最佳答案

正确的语法是--system-header-prefix=value。 (参见 https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers)

但是,它应该像您预期的那样被视为系统 header ,因为默认情况下它应该有这个:-internal-isystem/usr/local/include

要诊断发生这种情况的原因,您需要从驱动程序发送到前端的完整命令。请添加 -### 以查看完整命令。

关于c++ - clang 不应该抑制来自/usr/local/include 中头文件的警告吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48096872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com