Clang含有大量不需要的标题

时间:2018-04-09 11:41:15

标签: c++ macos clang macos-high-sierra

给出以下代码:

#include<iostream>

int main()
{

return 0;
}

当我尝试编译这个简单的代码时,clang隐含地包含了我想要的 iosteram 中的一堆其他标题。

因此使用-M标志来编写依赖项:

$ clang main.cpp -M

输出是:

  /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__config \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/ios \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h \
  /usr/include/wchar.h /usr/include/_types.h /usr/include/sys/_types.h \
  /usr/include/sys/cdefs.h /usr/include/sys/_symbol_aliasing.h \
  /usr/include/sys/_posix_availability.h /usr/include/machine/_types.h \
  /usr/include/i386/_types.h /usr/include/sys/_pthread/_pthread_types.h \
  /usr/include/Availability.h /usr/include/AvailabilityInternal.h \
  /usr/include/sys/_types/_null.h /usr/include/sys/_types/_size_t.h \
  /usr/include/sys/_types/_mbstate_t.h /usr/include/machine/types.h \
  /usr/include/i386/types.h /usr/include/sys/_types/_int8_t.h \
  /usr/include/sys/_types/_int16_t.h /usr/include/sys/_types/_int32_t.h \
  /usr/include/sys/_types/_int64_t.h /usr/include/sys/_types/_u_int8_t.h \
  /usr/include/sys/_types/_u_int16_t.h \
  /usr/include/sys/_types/_u_int32_t.h \
  /usr/include/sys/_types/_u_int64_t.h \
  /usr/include/sys/_types/_intptr_t.h \
  /usr/include/sys/_types/_uintptr_t.h \
  /usr/include/sys/_types/_ct_rune_t.h /usr/include/sys/_types/_rune_t.h \
  /usr/include/sys/_types/_wchar_t.h \
  /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stdarg.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h \
  /usr/include/stdio.h /usr/include/_stdio.h \
  /usr/include/sys/_types/_va_list.h /usr/include/sys/stdio.h \
  /usr/include/sys/_types/_off_t.h /usr/include/sys/_types/_ssize_t.h \
  /usr/include/time.h /usr/include/sys/_types/_clock_t.h \
  /usr/include/sys/_types/_time_t.h /usr/include/sys/_types/_timespec.h \
  /usr/include/_wctype.h /usr/include/__wctype.h \
  /usr/include/sys/_types/_wint_t.h /usr/include/_types/_wctype_t.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/ctype.h \
  /usr/include/ctype.h /usr/include/_ctype.h /usr/include/runetype.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/string \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__string \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/initializer_list \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cstddef \
  /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stddef.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__nullptr \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cstring \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/string.h \
  /usr/include/string.h /usr/include/sys/_types/_rsize_t.h \
  /usr/include/sys/_types/_errno_t.h /usr/include/strings.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/utility \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__tuple \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/stdint.h \
  /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/stdint.h \
  /usr/include/stdint.h /usr/include/_types/_uint8_t.h \
  /usr/include/_types/_uint16_t.h /usr/include/_types/_uint32_t.h \
  /usr/include/_types/_uint64_t.h /usr/include/_types/_intmax_t.h \
  /usr/include/_types/_uintmax_t.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__debug \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/memory \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/typeinfo \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/exception \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h \
  /usr/include/stdlib.h /usr/include/sys/wait.h \
  /usr/include/sys/_types/_pid_t.h /usr/include/sys/_types/_id_t.h \
  /usr/include/sys/signal.h /usr/include/sys/appleapiopts.h \
  /usr/include/machine/signal.h /usr/include/i386/signal.h \
  /usr/include/machine/_mcontext.h /usr/include/i386/_mcontext.h \
  /usr/include/mach/machine/_structs.h /usr/include/mach/i386/_structs.h \
  /usr/include/sys/_pthread/_pthread_attr_t.h \
  /usr/include/sys/_types/_sigaltstack.h \
  /usr/include/sys/_types/_ucontext.h \
  /usr/include/sys/_types/_sigset_t.h /usr/include/sys/_types/_uid_t.h \
  /usr/include/sys/resource.h /usr/include/sys/_types/_timeval.h \
  /usr/include/machine/endian.h /usr/include/i386/endian.h \
  /usr/include/sys/_endian.h /usr/include/libkern/_OSByteOrder.h \
  /usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h \
  /usr/include/sys/_types/_dev_t.h /usr/include/sys/_types/_mode_t.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/new \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/limits \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__undef_macros \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/iterator \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__functional_base \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__functional_base_03 \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/tuple \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/stdexcept \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cassert \
  /usr/include/assert.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/atomic \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdio \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cwchar \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cwctype \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cctype \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/wctype.h \
  /usr/include/wctype.h /usr/include/_types/_wctrans_t.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/mutex \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__mutex_base \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/chrono \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/ctime \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/ratio \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/climits \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/limits.h \
  /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include/limits.h \
  /usr/include/limits.h /usr/include/machine/limits.h \
  /usr/include/i386/limits.h /usr/include/i386/_limits.h \
  /usr/include/sys/syslimits.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/system_error \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/cerrno \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/errno.h \
  /usr/include/errno.h /usr/include/sys/errno.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support \
  /usr/include/pthread.h /usr/include/pthread/pthread_impl.h \
  /usr/include/pthread/sched.h \
  /usr/include/sys/_pthread/_pthread_cond_t.h \
  /usr/include/sys/_pthread/_pthread_condattr_t.h \
  /usr/include/sys/_pthread/_pthread_key_t.h \
  /usr/include/sys/_pthread/_pthread_mutex_t.h \
  /usr/include/sys/_pthread/_pthread_mutexattr_t.h \
  /usr/include/sys/_pthread/_pthread_once_t.h \
  /usr/include/sys/_pthread/_pthread_rwlock_t.h \
  /usr/include/sys/_pthread/_pthread_rwlockattr_t.h \
  /usr/include/sys/_pthread/_pthread_t.h /usr/include/pthread/qos.h \
  /usr/include/sys/qos.h /usr/include/sys/_types/_mach_port_t.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/functional \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__functional_03 \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/locale.h \
  /usr/include/locale.h /usr/include/_locale.h /usr/include/xlocale.h \
  /usr/include/_xlocale.h /usr/include/xlocale/_ctype.h \
  /usr/include/xlocale/__wctype.h /usr/include/xlocale/_stdio.h \
  /usr/include/xlocale/_stdlib.h /usr/include/xlocale/_string.h \
  /usr/include/xlocale/_time.h /usr/include/xlocale/_wchar.h \
  /usr/include/xlocale/_wctype.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/streambuf \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/istream \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/ostream \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/locale \
  /usr/include/nl_types.h /usr/include/sys/types.h \
  /usr/include/sys/_types/_u_char.h /usr/include/sys/_types/_u_short.h \
  /usr/include/sys/_types/_u_int.h /usr/include/sys/_types/_caddr_t.h \
  /usr/include/sys/_types/_blkcnt_t.h \
  /usr/include/sys/_types/_blksize_t.h /usr/include/sys/_types/_gid_t.h \
  /usr/include/sys/_types/_in_addr_t.h \
  /usr/include/sys/_types/_in_port_t.h /usr/include/sys/_types/_ino_t.h \
  /usr/include/sys/_types/_ino64_t.h /usr/include/sys/_types/_key_t.h \
  /usr/include/sys/_types/_nlink_t.h \
  /usr/include/sys/_types/_useconds_t.h \
  /usr/include/sys/_types/_suseconds_t.h \
  /usr/include/sys/_types/_fd_def.h \
  /usr/include/sys/_types/_fd_setsize.h \
  /usr/include/sys/_types/_fd_set.h /usr/include/sys/_types/_fd_clr.h \
  /usr/include/sys/_types/_fd_zero.h /usr/include/sys/_types/_fd_isset.h \
  /usr/include/sys/_types/_fd_copy.h \
  /usr/include/sys/_types/_fsblkcnt_t.h \
  /usr/include/sys/_types/_fsfilcnt_t.h /usr/include/_types/_nl_item.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__bsd_locale_defaults.h \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/bitset \
  /Library/Developer/CommandLineTools/usr/include/c++/v1/__bit_reference

请注意,输出的第一行是我在main.cpp文件中明确包含在 #indlude 指令中的有用标题。其余标题是多余的。

我认为clang包含了这些标题,以及那些忘记包含必要标题的程序员的视图。 但是如何禁用此行为,即如何告诉clang不要包含这些标题?

1 个答案:

答案 0 :(得分:1)

iostream包含或传递所有这些标题。

对于你想要做的工作,我建议看看clangd:https://clang.llvm.org/extra/clangd.html