我正在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=/usr/local/include
吗?http://clang.llvm.org/docs/UsersManual.html - Richard Hodges