# Include What You Use #
[![IWYU CI](https://github.com/include-what-you-use/include-what-you-use/actions/workflows/ci.yml/badge.svg)](https://github.com/include-what-you-use/include-what-you-use/actions/workflows/ci.yml)
For more in-depth documentation, see [docs](docs).
## Instructions for users ##
"Include what you use" means this: for every symbol (type, function, variable, or macro) that you use in `foo.cc` (or `foo.cpp`), either `foo.cc` or `foo.h` should include a .h file that exports the declaration of that symbol. (Similarly, for `foo_test.cc`, either `foo_test.cc` or `foo.h` should do the including.) Obviously symbols defined in `foo.cc` itself are excluded from this requirement.
This puts us in a state where every file includes the headers it needs to declare the symbols that it uses. When every file includes what it uses, then it is possible to edit any file and remove unused headers, without fear of accidentally breaking the upwards dependencies of that file. It also becomes easy to automatically track and update dependencies in the source code.
### CAVEAT ###
This is alpha quality software -- at best (as of July 2018). It was originally written to work specifically in the Google source tree, and may make assumptions, or have gaps, that are immediately and embarrassingly evident in other types of code.
While we work to get IWYU quality up, we will be stinting new features, and will prioritize reported bugs along with the many existing, known bugs. The best chance of getting a problem fixed is to submit a patch that fixes it (along with a test case that verifies the fix)!
### Clang compatibility ###
Include-what-you-use makes heavy use of Clang internals, and will occasionally break when Clang is updated. We build IWYU regularly against Clang mainline to detect and fix such compatibility breaks as soon as possible.
NOTE: the IWYU master branch follows Clang main branch.
We also have convenience tags and branches for released versions of Clang (called `clang_<version>`, e.g. `clang_5.0`). To build against a Clang release, check out the corresponding branch in IWYU before configuring the build. You can use this mapping table to combine Clang and IWYU versions correctly:
| Clang | IWYU version | IWYU branch |
|-------|--------------|----------------|
| 3.6 | 0.4 | `clang_3.6` |
| 3.7 | 0.5 | `clang_3.7` |
| 3.8 | 0.6 | `clang_3.8` |
| 3.9 | 0.7 | `clang_3.9` |
| 4.0 | 0.8 | `clang_4.0-r2` |
| 5.0 | 0.9 | `clang_5.0` |
| 6 | 0.10 | `clang_6.0` |
| 7 | 0.11 | `clang_7.0` |
| 8 | 0.12 | `clang_8.0` |
| 9 | 0.13 | `clang_9.0` |
| 10 | 0.14 | `clang_10` |
| 11 | 0.15 | `clang_11` |
| 12 | 0.16 | `clang_12` |
| 13 | 0.17 | `clang_13` |
| 14 | 0.18 | `clang_14` |
| 15 | 0.19 | `clang_15` |
| 16 | 0.20 | `clang_16` |
| 17 | 0.21 | `clang_17` |
| ... | ... | ... |
| main | | `master` |
> NOTE: If you use the Debian/Ubuntu packaging available from <https://apt.llvm.org>, you'll need the following packages installed:
>
> * `llvm-<version>-dev`
> * `libclang-<version>-dev`
> * `clang-<version>`
>
> Packaging for other platforms will likely be subtly different.
### How to build standalone ###
This build mode assumes you already have compiled LLVM and Clang libraries on your system, either via packages for your platform or built from source. To set up an environment for building IWYU:
* Create a directory for IWYU development, e.g. `iwyu`
* Clone the IWYU Git repo:
iwyu$ git clone https://github.com/include-what-you-use/include-what-you-use.git
* Presumably, you'll be building IWYU with a released version of LLVM and Clang, so check out the corresponding branch. For example, if you have Clang 6.0 installed, use the `clang_6.0` branch. IWYU `master` tracks LLVM & Clang `main`:
iwyu$ cd include-what-you-use
iwyu/include-what-you-use$ git checkout clang_6.0
* Create a build root and use CMake to generate a build system linked with LLVM/Clang prebuilts:
# This example uses the Makefile generator, but anything should work.
iwyu/include-what-you-use$ cd ..
iwyu$ mkdir build && cd build
# For IWYU 0.10/Clang 6 and earlier
iwyu/build$ cmake -G "Unix Makefiles" -DIWYU_LLVM_ROOT_PATH=/usr/lib/llvm-6.0 ../include-what-you-use
# For IWYU 0.11/Clang 7 and later
iwyu/build$ cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 ../include-what-you-use
(substitute the `llvm-6.0` or `llvm-7` suffixes with the actual version compatible with your IWYU branch)
or, if you have a local LLVM and Clang build tree, you can specify that as `CMAKE_PREFIX_PATH` for IWYU 0.11 and later:
iwyu/build$ cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=~/llvm-project/build ../include-what-you-use
* Once CMake has generated a build system, you can invoke it directly from `build`, e.g.
iwyu/build$ make
### How to build as part of LLVM ###
Instructions for building LLVM and Clang are available at <https://clang.llvm.org/get_started.html>.
To include IWYU in the LLVM build, use the `LLVM_EXTERNAL_PROJECTS` and `LLVM_EXTERNAL_*_SOURCE_DIR` CMake variables when configuring LLVM:
llvm-project/build$ cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXTERNAL_PROJECTS=iwyu -DLLVM_EXTERNAL_IWYU_SOURCE_DIR=/path/to/iwyu /path/to/llvm-project/llvm
llvm-project/build$ make
This builds all of LLVM, Clang and IWYU in a single tree.
### How to install ###
If you're building IWYU out-of-tree or installing pre-built binaries, you need to make sure it can find Clang built-in headers (`stdarg.h` and friends.)
Clang's default policy is to look in `path/to/clang-executable/../lib/clang/<clang ver>/include`. So if Clang 3.5.0 is installed in `/usr/bin`, it will search for built-ins in `/usr/lib/clang/3.5.0/include`.
Clang tools have the same policy by default, so in order for IWYU to analyze any non-trivial code, it needs to find Clang's built-ins in `path/to/iwyu/../lib/clang/3.5.0/include` where `3.5.0` is a stand-in for the version of Clang your IWYU was built against.
Note that some distributions/packages may have different defaults, you can use `clang -print-resource-dir` to find the base path of the built-in headers on your system.
So for IWYU to function correctly, you need to copy the Clang `include` directory to the expected location before running (similarly, use `include-what-you-use -print-resource-dir` to learn exactly where IWYU wants the headers).
This weirdness is tracked in [issue 100](https://github.com/include-what-you-use/include-what-you-use/issues/100), hopefully we can make this more transparent over time.
### How to run ###
The original design was built for Make, but a number of alternative run modes have come up over the years.
#### Running on single source file ####
The simplest way to use IWYU is to run it against a single source file:
include-what-you-use $CXXFLAGS myfile.cc
where `$CXXFLAGS` are the flags you would normally pass to the compiler.
#### Plugging into existing build system ####
Typically there is already a build system containing the relevant compiler flags for all source files. Replace your compiler with `include-what-you-use` to generate a large batch of IWYU advice. Depending on your build system/build tools, this can take many forms, but for a simple GNU Make system it might look like this:
make -k CXX=include-what-you-use CXXFLAGS="-Xiwyu --error_always"
(The additional `-Xiwyu --error_always` switch makes `include-what-you-use` always exit with an error code, so the build system knows it didn't build a .o file. Hence the need for `-k`.)
In this mode `include-what-you-use` only analyzes the .
没有合适的资源?快使用搜索试试~ 我知道了~
A tool for use with clang to analyze .zip
共636个文件
h:364个
cc:189个
c:29个
需积分: 5 0 下载量 192 浏览量
2023-12-31
10:00:57
上传
评论
收藏 1006KB ZIP 举报
温馨提示
A tool for use with clang to analyze .zip
资源推荐
资源详情
资源评论
收起资源包目录
A tool for use with clang to analyze .zip (636个子文件)
include-what-you-use.1 10KB
elaborated_struct.c 2KB
exitcode_warn_error_always_arg.c 1KB
exitcode_warn_error_always.c 1KB
libbuiltins.c 986B
exitcode_warn_error_and_always.c 957B
exitcode_warn_error.c 949B
exitcode_warn_error_arg.c 941B
offload_openmp.c 925B
exitcode_warn.c 872B
enum.c 823B
multiple_inputs.c 778B
keep_includes.c 766B
generate_pch.c 746B
compile_and_link.c 740B
offload_apple.c 687B
no_h_includes_cc-inc2.c 656B
exitcode_good_error_arg.c 641B
save_temps.c 638B
exitcode_good_error.c 633B
exitcode_good_error_always_arg.c 600B
exitcode_good_error_always.c 590B
exitcode_syntax_error.c 590B
exitcode_good_error_and_always.c 587B
no_h_includes_cc-inc.c 558B
preprocess_msvc.c 532B
exitcode_good.c 519B
preprocess_gcc.c 503B
exitcode_bad_args.c 496B
badinc2.c 432B
iwyu.cc 177KB
iwyu_output.cc 93KB
iwyu_include_picker.cc 86KB
badinc.cc 77KB
iwyu_ast_util.cc 59KB
iwyu_preprocessor.cc 48KB
iwyu_globals.cc 23KB
iwyu_output_test.cc 22KB
iwyu_stricter_than_cpp.cc 20KB
iwyu_include_picker_test.cc 15KB
comment_pragmas.cc 11KB
iwyu_driver.cc 10KB
fwd_decl_nested_class.cc 9KB
funcptrs.cc 8KB
iwyu_lexer_utils_test.cc 8KB
iwyu_location_util.cc 8KB
template_args.cc 7KB
iwyu_getopt.cc 7KB
iwyu_path_util.cc 7KB
placement_new.cc 6KB
precomputed_tpl_args.cc 6KB
ptr_ref_aliases.cc 6KB
member_expr.cc 5KB
derived_function_tpl_args.cc 5KB
explicit_instantiation.cc 5KB
sizeof_reference.cc 4KB
typedef_in_template.cc 4KB
explicit_instantiation2.cc 4KB
elaborated_type.cc 4KB
iwyu_string_util_test.cc 4KB
iwyu_cache.cc 4KB
enums.cc 3KB
pointer_arith.cc 3KB
precomputed_tpl_args_cpp14.cc 3KB
macro_defined_by_includer.cc 3KB
virtual_tpl_method.cc 3KB
iwyu_lexer_utils.cc 3KB
operator_new.cc 3KB
catch.cc 3KB
implicit_ctor.cc 3KB
default_template_arg_other_file.cc 3KB
iwyu_regex.cc 3KB
include_with_using.cc 2KB
prefix_header_includes_add.cc 2KB
array.cc 2KB
template_specialization.cc 2KB
pragma_keep_multi.cc 2KB
no_fwd_decls.cc 2KB
expl_inst_select.cc 2KB
associated_skipped.cc 2KB
typedef_chain_in_template.cc 2KB
typedefs_and_resugaring.cc 2KB
prefix_header_includes_keep.cc 2KB
prefix_header_includes_remove.cc 2KB
forward_declare_in_macro.cc 2KB
alias_template.cc 2KB
deleted_implicit.cc 2KB
lateparsed_template.cc 2KB
binary_type_trait.cc 2KB
using_aliased_symbol.cc 2KB
casts.cc 2KB
iterator.cc 2KB
typedef_chain_no_follow.cc 2KB
pch_in_code.cc 2KB
out_of_line.cc 2KB
template_base.cc 2KB
varargs_and_references.cc 2KB
macro_location_tpl.cc 2KB
anonymous_struct.cc 2KB
backwards_includes.cc 2KB
共 636 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
暮苍梧~
- 粉丝: 41
- 资源: 258
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课设毕设基于SSM的旅游景点线路网站 LW+PPT+源码可运行.zip
- EDA实验计数器CNT9999-DTCNT9999实验源代码
- 课设毕设基于SSM的抗疫医疗用品销售平台 LW+PPT+源码可运行.zip
- 基于Halcon的仿照VisonPro的机器视觉软件.zip
- battery-percentage-detector 使用 Javascript 的电池百分比检测器
- 毕业设计基于Qt+FFmpeg+SDL实现的音视频播放器源码.zip
- 课设毕设基于SSM的固定资产管理系统 LW+PPT+源码可运行.zip
- 课设毕设基于SSM的个人交友网站 LW+PPT+源码可运行.zip
- 课设毕设基于SSM的高校信息资源共享平台 LW+PPT+源码可运行.zip
- 课设毕设基于SSM的高校二手交易平台 LW+PPT+源码可运行.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功