Reputation: 2115
So I have below code in my file mine.cpp,
#include <iostream>
#define max INT_MAX
The identifier "INT_MAX" will be undefined if I remove "#include <iostream>". So, I know it is defined somewhere in iostream.
When I go to the definition of INT_MAX it is in limits.h file. So, I guess limits.h is nested include in iostream.
Is there a way for me to view (like mine.cpp->iostream->...->limits.h) how limits.h is included in my mine.cpp without building.
I searched and found there are other similar questions but all answers related to them include "build with some option". I have to do this without building as my build takes quite some time to complete.
Upvotes: 1
Views: 436
Reputation: 11311
That's a strange requirement:
without building.
What exactly are you trying to avoid? Building the entire project/solution? To save time?
As noted by @dxiv and @Boris, you need to at least compile that file. More strictly - run a pre-processor on it to expand macros, conditional compilation, etc.
Compiling you file with /showIncludes
and /P
(preprocess to a file) technically doesn't "build", as the object file is not produced.
The generated output is hierarchical, so you get a complete path of inclusion.
You didn't mention the version and edition of your Studio; this post Generate graph of include files in Visual Studio Community 2019 states that Enterprise edition of 2019 (and possible 2017) has "Generate Graph Of Include Files"
feature. However, the process that it is using likely involves compiling or preprocessing :)
Upvotes: 1
Reputation: 17648
Don't know that it is (reliably) possible to do it without at least compiling, since in the end it's the compiler that checks the include paths and dependencies.
However, compiling a single file with #include <iostream>
should suffice, as opposed to building the entire project. For example, compiling the default "C++ console" .cpp
generated by the wizard produces a debug\sample.tlog\CL.read.1.tlog
file which contains the following towards the top.
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\IOSTREAM ***
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\YVALS_CORE.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\VCRUNTIME.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\SAL.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\CONCURRENCYSAL.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\VADEFS.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\XKEYCHECK.H
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\ISTREAM ***
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\OSTREAM ***
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\IOS
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\XLOCNUM ***
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\CLIMITS ***
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\LIMITS.H <--
<vs-path>\VC\TOOLS\MSVC\14.26.28801\INCLUDE\CMATH
The above is a superset of the #include
files that lead to limits.h
. An inspection of the respective headers shows that the actual path is iostream
- istream
- ostream
- xlocnum
- climits
- limits.h
.
Upvotes: 1