不应该在 /usr/local/include 中抑制来自头文件的警告吗?
Shouldn't clang suppress warnings from a header file in /usr/local/include?
我正在OSX上构建一个使用Boost.Log的应用程序。当我将警告标志设置为包含-Wextra
时,我收到有关其中一个 Boost 头文件中未使用参数的警告。
女工程师:
#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
中的任何内容都会被视为系统标头,因此其警告被抑制,但显然不是。
我也尝试添加--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(
但是,它应该像您预期的那样被视为系统标头,因为默认情况下它应该具有以下内容:-internal-isystem /usr/local/include
要诊断发生这种情况的原因,您需要从驱动程序发送到前端的完整命令。请添加-###
以查看完整的命令。
相关文章:
- 禁止显示有关包含文件中 #pragma 包的警告
- MSVC 杂注警告省略 CPP 文件中的'default'
- 警告被视为错误 - 未生成"对象"文件
- Xcode 8.3.2 中的错误警告:文件的非可移植路径 - 指定的路径与磁盘上的文件名不同
- 不应该在 /usr/local/include 中抑制来自头文件的警告吗?
- 生成文件:此警告的名称是什么?
- 当外部变量在其他文件中声明不同时,如何使G 产生警告
- 警告:打开错误文件(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.
- 错误 C2220:警告被视为驱动程序开发中生成的错误无'object'文件
- 将终端上的所有消息和警告打印到文件中
- 禁用特定包含文件的警告
- 编译 c++ 与 -Wall - 来自其他文件的警告
- 警告 C4819 在 Visual Studio C++ 2013 Express - 没有 BOM 的 UTF8 文件
- g++:有没有办法警告头文件是否不包含在文件中
- 如何禁用非项目文件中的警告?---Visual Studio 2010
- 错误 C2220:警告被视为错误 - 未生成"对象"文件
- 在没有警告提示的情况下打开文件
- 如何在使用g++构建时抑制某些文件中的警告
- gdb 7.0警告:核心文件中的fpregset大小错误
- 使用GCC/GMake预编译头文件导致' pragma '警告(Premake)