Binaries for Windows (or simplified build from source)

1,238 views
Skip to first unread message

Mikhail Matrosov

unread,
May 28, 2014, 7:20:17 AM5/28/14
to include-wh...@googlegroups.com
I'm using IWYU under Windows with Visual Studio 2010 projects with the binary include-what-you-use-3.4-win32.zip. I have a several issues to report, but they might have been already fixed in the latest versions. 

When to expect tha latest binaries for windows? Or could you simplify build from sources under Windows? Instructions posted here look a little frustrating ("Build, fix errors, repeat" - huh? O_o)

Thanks.

PS Here is the command line I use for my VS projects, maybe you will suggest something better (^ means line continuation in ugly windows .bat-files):

include-what-you-use.exe ^
-I "c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Include" ^
-I "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include" ^
-DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL ^
-w -x c++ -std=c++11 -fcxx-exceptions -fexceptions -fms-compatibility -fms-extensions -fmsc-version=1600 -Wno-invalid-token-paste ^
-include stdafx.h ^
-Xiwyu --verbose=3 -Xiwyu --transitive_includes_only ^
MyHeader.h

Kim Gräsman

unread,
May 28, 2014, 1:46:16 PM5/28/14
to include-wh...@googlegroups.com
Hi Mikhail,

So far we've only shipped IWYU binaries whenever LLVM/Clang makes a
release, so expect a new IWYU release when Clang 3.5 comes out.

I build from source on Windows routinely, everything should work
there. Follow instructions here (I recommend the in-tree build, it
works best):
https://code.google.com/p/include-what-you-use/wiki/InstructionsForUsers#How_to_Build

Unfortunately, Clang and LLVM now require VS2012 to build and,
consequently, so does IWYU.

As for compatibility, IWYU is at the same level as Clang, so if Clang
can parse a file, IWYU generally can too (there are some IWYU-specific
exceptions to that rule.)

Depending on what you want to do, your command-line looks fine. Clang
has grown compatibility switches for Microsoft's C++ compiler, so you
might be able to use your compiler switches directly as specified in
VS -> Project Settings -> Command Line, depending on how full their
support is.

For what it's worth,
- Kim
> --
> You received this message because you are subscribed to the Google Groups
> "include-what-you-use" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to include-what-you...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mikhail Matrosov

unread,
May 29, 2014, 3:51:38 AM5/29/14
to include-wh...@googlegroups.com
Hello, Kim.

Thanks for the feedback, I will try to build IWYU for windows from sources.

Meanwhile, I wish to know, whether the following behavior is a bug or not. I have three header files:

-------------- A.h ----------------
class A
{
public:
  int foo() { return 1; }
};

-------------- B.h ----------------
#include "A.h"
class B : public A
{
public:
  int bar() { return 2; }
};

-------------- main.h ----------------
#include "B.h"
class Main : public B
{
public:
  int DoWork(A* pa) { return pa->foo(); }
};

When I run IWYU on main.h with the command line I specified, I have the following result:

main.h should add these lines:
#include "A.h"                          // for A

main.h should remove these lines:

The full include-list for main.h:
#include "A.h"                          // for A
#include "B.h"                          // for B

It suggests to add A.h. But A.h is obviously indirectly included from B.h, since B inherits from A. Note that I specified --transitive_includes_only option, but it seem to have no effect (same result without the option). Am I doing something wrong, or is this behaviour correct? If yes, is there a way to override it? Because I don't want to include A.h here.

-----
Best regards, Mikhail Matrosov


You received this message because you are subscribed to a topic in the Google Groups "include-what-you-use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/include-what-you-use/xCGfWp9w5kM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to include-what-you...@googlegroups.com.

Kim Gräsman

unread,
May 29, 2014, 4:46:59 AM5/29/14
to include-wh...@googlegroups.com
Hello Mikhail,

On Thu, May 29, 2014 at 9:51 AM, Mikhail Matrosov
<mikhail....@gmail.com> wrote:
>
> It suggests to add A.h. But A.h is obviously indirectly included from B.h,
> since B inherits from A. Note that I specified --transitive_includes_only
> option, but it seem to have no effect (same result without the option). Am I
> doing something wrong, or is this behaviour correct? If yes, is there a way
> to override it? Because I don't want to include A.h here.

I think --transitive_includes_only does the opposite of what you want.
It seems to say includes are only added if they're already indirectly
included. You want to suppress adding if they're already indirectly
included.

This reminds me of:
https://code.google.com/p/include-what-you-use/issues/detail?id=73

An interesting detail here: if you look at main.h, there's nothing in
there that uses the aspects for which it's included in b.h. We don't
call foo indirectly through B or anything, so it could be argued that
Main's dependency on A is independent of B's dependency on A. That
said, I don't think IWYU is smart enough to reason like that, but I
still think it's right to put a.h into main.h.

Take a look at the export pragma for how to force IWYU to see through
the indirect dependency:
https://code.google.com/p/include-what-you-use/wiki/IWYUPragmas#IWYU_pragma:_export

Hope that helps,
- Kim

Mikhail Matrosov

unread,
May 29, 2014, 7:26:54 AM5/29/14
to include-wh...@googlegroups.com
Hello, Kim.

Main's dependency on A is independent of B's dependency on A

I don't get it. Main is dependent on B and B is dependent on A, so Main is dependent on A in any case (dependencies are transitive, right?). I don't think explicit #include of A.h will reveal any dependencies or intentions. I think it will only pollute the code. Why IWYU thinks differently? Am I missing something?

Thanks for the links, seems like pragma export does exactly what I want.


-----
Best regards, Mikhail Matrosov


Kim Gräsman

unread,
May 29, 2014, 9:07:27 AM5/29/14
to include-wh...@googlegroups.com
On Thu, May 29, 2014 at 1:26 PM, Mikhail Matrosov
<mikhail....@gmail.com> wrote:
> Hello, Kim.
>
>> Main's dependency on A is independent of B's dependency on A
>
>
> I don't get it. Main is dependent on B and B is dependent on A, so Main is
> dependent on A in any case (dependencies are transitive, right?). I don't
> think explicit #include of A.h will reveal any dependencies or intentions. I
> think it will only pollute the code. Why IWYU thinks differently? Am I
> missing something?

IWYU's mission is not to minimize #includes, but to *include* what you *use*.

The fact that B depends on A is an implementation detail of B, and
we'd like to keep Main's #includes independent of implementation
details so as to ease refactoring (e.g. if we changed B to no longer
derive from A.)

So dependencies in general are not transitive to IWYU, I think, but
there are a few cases where convention beats dogma, see for example:
https://code.google.com/p/include-what-you-use/wiki/WhatIsAUse#Author_Intent

- Kim

Mikhail Matrosov

unread,
May 29, 2014, 12:50:52 PM5/29/14
to include-wh...@googlegroups.com
Oh, now I get it. IWYU is a bit more clever than I thought. Thanks, Kim!


-----
Best regards, Mikhail Matrosov



- Kim

Mikhail Matrosov

unread,
May 29, 2014, 12:53:39 PM5/29/14
to include-wh...@googlegroups.com
One more question, how do you pronounce IWYU? :)


-----
Best regards, Mikhail Matrosov


Kim Gräsman

unread,
May 29, 2014, 3:11:45 PM5/29/14
to include-wh...@googlegroups.com
I rarely talk about it orally, but I tend to say
"include-what-you-use" or the individual characters "i-w-y-u". It's a
terrible name :-)

- Kim

On Thu, May 29, 2014 at 6:53 PM, Mikhail Matrosov
> You received this message because you are subscribed to the Google Groups
> "include-what-you-use" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages