LukasScheucher / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

iwyu built against MacPorts LLVM-3.3 prelease can't find stdarg.h #100

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?  Give the *exact* arguments passed
to include-what-you-use, and attach the input source file that gives the
problem (minimal test-cases are much appreciated!)
1. Run IWYU against the following file:
➜  iwyu  clear
➜  iwyu  cat ./cstdarg.cpp
#include <cstdarg>

int main(int argc, char* argv[]) {
    return 0;
}.

What is the expected output? What do you see instead?

I'd expect this file to compile without warnings or errors. Potentially, IWYU 
might tell me that cstdarg is not needed. However, what I actually get is a 
compilation error:

➜  iwyu  include-what-you-use ./cstdarg.cpp
In file included from ./cstdarg.cpp:1:
/usr/include/c++/4.2.1/cstdarg:51:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
         ^

/usr/include/c++/4.2.1/cstdarg should add these lines:

/usr/include/c++/4.2.1/cstdarg should remove these lines:
- #include <bits/c++config.h>  // lines 50-50

The full include-list for /usr/include/c++/4.2.1/cstdarg:

---

(cstdarg.cpp has correct #includes/fwd-decls)

What version of the product are you using? On what operating system?
I'm using r472 on OS X 10.8 built against MacPorts LLVM 3.3 prerelease:
➜  iwyu  port list clang-3.3 llvm-3.3
clang-3.3                      @3.3-r180025    lang/llvm-3.3
llvm-3.3                       @3.3-r180025    lang/llvm-3.3

Please provide any additional information below.

Original issue reported on code.google.com by andrew.c.morrow@gmail.com on 29 Jun 2013 at 6:18

GoogleCodeExporter commented 8 years ago
Can you compile cstdarg.cpp with clang-3.3? Looks like you are hitting 
http://clang.llvm.org/docs/FAQ.html#i-get-errors-about-some-headers-being-missin
g-stddef-h-stdarg-h

With current LLVM/Clang and IWYU I see the following output

/usr/include/c++/4.2.1/cstdarg should add these lines:
#include <cstddef>                      // for _GLIBCXX_BEGIN_NAMESPACE, etc

/usr/include/c++/4.2.1/cstdarg should remove these lines:
- #include <bits/c++config.h>  // lines 50-50

The full include-list for /usr/include/c++/4.2.1/cstdarg:
#include <stdarg.h>                     // for va_end, va_list
#include <cstddef>                      // for _GLIBCXX_BEGIN_NAMESPACE, etc
---

(cstdarg.cpp has correct #includes/fwd-decls)

Original comment by vsap...@gmail.com on 30 Jun 2013 at 6:31

GoogleCodeExporter commented 8 years ago
Volodymyr, I think IWYU is confused because your source file is named 
"cstdarg.cpp"; it considers "cstdarg" its associated header and tries to 
suggest improvements for it.

I think the built-in include search is different on MSVC/Windows, so I can't 
reproduce here.

Original comment by kim.gras...@gmail.com on 30 Jun 2013 at 7:05

GoogleCodeExporter commented 8 years ago
Since issue-99 had turned out to be resolved by rebuilding against the 
clang-3.3 stable, I tried this one again. It still has problems. I also renamed 
the file from cstdarg.cpp to blah.cpp to avoid the issue mentioned above. I 
still find that it errors out. However, I found that if I explicitly include 
the include path to the llvm-3.3 directory containing its stdarg.h, then all is 
well:

➜  cat ./blah.cpp
#include <cstdarg>

int main(int argc, char* argv[]) {
    va_list list;
    return 0;
}
➜  ./include-what-you-use ./blah.cpp
In file included from ./blah.cpp:1:
/usr/include/c++/4.2.1/cstdarg:51:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
         ^

blah.cpp should add these lines:

blah.cpp should remove these lines:
- #include <cstdarg>  // lines 1-1

The full include-list for blah.cpp:
---

Here it is with the additional include path:

➜  ./include-what-you-use ./blah.cpp 
-I/opt/local/libexec/llvm-3.3/lib/clang/3.3/include/

(blah.cpp has correct #includes/fwd-decls)

So this suggests to me that when building IWYU it isn't incorporating 'builtin' 
LLVM/clang header paths somehow.

Original comment by andrew.c.morrow@gmail.com on 1 Jul 2013 at 2:06

GoogleCodeExporter commented 8 years ago
Per the link posted earlier, Clang searches for its builtin headers relative to 
the binary. I think the same rule applies for IWYU.

This suggests you should move the include-what-you-use executable to the same 
directory as clang, or copy the builtin includes and libs from 
/opt/local/libexec/llvm-33/lib/clang/3.3 to just next to include-what-you-use.

I still can't repro here, neither on Windows nor Ubuntu, but I'm not sure what 
headers it finds and how. This is a bit of a problem with Clang, I think, that 
its header search algorithm depends on what platform it was built on.

Note that if you build IWYU, Clang and LLVM together, this never becomes a 
problem, because include-what-you-use will end up next to clang in the install 
tree.

I'd love to hear if you can get it to work by copying include and lib from 
clang/3.3, and then we can think about a more transparent solution.

Original comment by kim.gras...@gmail.com on 1 Jul 2013 at 7:02

GoogleCodeExporter commented 8 years ago
This applies to LLVM 3.5 in MacPorts as well. Doing a regular build with 
clang++-mp-3.5 shows no problem, so it's iwyu related.

Original comment by dsvens...@gmail.com on 12 Feb 2014 at 12:19

GoogleCodeExporter commented 8 years ago
For what it's worth, I was running into the same problem with 3.4 and when I 
copied include-what-you-use to the same directory as clang, the problem went 
away. So it appears that the issue is caused by the headers that are shipped 
with clang not being resolved correctly when include-what-you-use is located in 
a different directory.

Original comment by davejohansen on 24 Apr 2014 at 8:27

GoogleCodeExporter commented 8 years ago
I ran this by the Clang development list and it seems we need to distribute the 
builtin headers with include-what-you-use.

Discussion here:
http://clang-developers.42468.n3.nabble.com/Standalone-tools-td4039043.html

And this is actually mentioned in passing here:
http://clang.llvm.org/docs/LibTooling.html#builtin-includes

I'll try and update our packaging script to include Clang's builtin headers.

Original comment by kim.gras...@gmail.com on 28 Apr 2014 at 6:02

GoogleCodeExporter commented 8 years ago
Do you want to add Clang's builtin headers to the distributed archive or to 
bake headers into IWYU binary?

Original comment by vsap...@gmail.com on 29 Apr 2014 at 1:01

GoogleCodeExporter commented 8 years ago
Since we have more than one build system, I thought I'd add the builtin headers 
to the archive as a first step, but ideally I'd like to bake the headers in.

Original comment by kim.gras...@gmail.com on 29 Apr 2014 at 4:03

GoogleCodeExporter commented 8 years ago
OK, so I've experimented a little bit in my local Windows working copy.

It seems that building a directory tree like this works reasonably well:

include-what-you-use/
  LICENSE.TXT
  README

  bin/
    include-what-you-use.exe
    fix_includes.py

  lib/
    clang/
      3.5.0/
        include/
          <built-in headers>

I can copy this anywhere, add the include-what-you-use/bin root to my path in a 
clean shell, and it works.

Does this look at all FHS-friendly?

@sylvestre on CC: How does this match what you're doing for Debian?

I wonder if we should add the equivalent of a make install step...?

Original comment by kim.gras...@gmail.com on 3 May 2014 at 8:12

GoogleCodeExporter commented 8 years ago
Actually, I am not sure how useful is a temporary fix by adding headers to 
distributed archives.  At least people in this thread haven't complained about 
distributed IWYU binary, they've built IWYU manually.

I was thinking about creating a file containing baked in builtin headers with a 
Python script.  Reasons for that: I am not very good with build systems; there 
will be less differences between different build systems.

Original comment by vsap...@gmail.com on 5 May 2014 at 9:35

GoogleCodeExporter commented 8 years ago
They're building out-of-tree and so run into the same problem -- they can only 
get IWYU to work if they put it in the Clang bin root.

But you're right; solving this in packaging won't help users building 
out-of-tree.

Yeah, a Python script sounds good, we should be able to run it from both CMake 
and Make. The example from Olivier Goffart seemed pretty straightforward and 
should port to Python easily.

I can build a draft implementation and we'll see how far it goes.

Original comment by kim.gras...@gmail.com on 6 May 2014 at 9:01

GoogleCodeExporter commented 8 years ago
I'm working on packaging IWYU for Fedora/RHEL so it can be easily installed 
using the standard "yum install" process on those platforms. In that case, the 
header files are already in the right place because both clang and IWYU are 
installed in the system directories. So if an option is added to copy/package 
the headers as part of the install process, then can an option to disable that 
please be added as well?
Thanks,
Dave

Original comment by davejohansen on 6 May 2014 at 3:09

GoogleCodeExporter commented 8 years ago
Kim, that looks great. Under Debian, I have clang installed here:
/usr/lib/llvm-3.5/lib/clang/3.5.0/include 

Original comment by sylvestre.ledru on 6 May 2014 at 3:40

GoogleCodeExporter commented 8 years ago
I've worked on embedding the headers, but I can't get it to work properly.

After convincing CMake to run the Python script, I now get a compiler error 
from MSVC that the string literals are larger than 64K. Since some of the 
builtin headers are in the 3-500K range, this seems hard to get around.

I'll take a break from this and come back to it, but ideas are welcome!

Original comment by kim.gras...@gmail.com on 11 May 2014 at 7:12

GoogleCodeExporter commented 8 years ago
I just symlink the lib folder from my Clang install to a folder named lib where 
the iwyu binary would expect it and it finds the builtins that way.

Original comment by ja...@citusdata.com on 25 Sep 2014 at 4:01

GoogleCodeExporter commented 8 years ago
Is there any fix or work-around which does not require root? I don't have root 
access to my machine and I would like to use IWYU.

I tried copying the folders from /usr/lib64/clang/3.5.0/* to my_iywu_folder/ 
but without success.

Original comment by ch.schmi...@gmail.com on 4 Dec 2014 at 1:04

GoogleCodeExporter commented 8 years ago
The relative path distance between /usr/bin/clang and /usr/lib/clang/<ver>/ 
needs to be preserved, so if you have the IWYU executable at 
~/my_iwyu_folder/include-what-you-use the builtins need to be at 
~/my_iwyu_folder/../lib/clang/<ver>/.

Also, <ver> needs to match the version IWYU was built for, double-check with 
`include-what-you-use --version` which Clang version it's built against.

Original comment by kim.gras...@gmail.com on 4 Dec 2014 at 7:13

GoogleCodeExporter commented 8 years ago
I built iwyu 0.3 with clang 3.5 on Fedora 21 and this issue seems to be fixed.

Original comment by davejohansen on 4 Feb 2015 at 11:59

GoogleCodeExporter commented 8 years ago
We haven't done anything actively, so chances are you've installed iwyu into 
/usr/bin or built in-tree with Clang or had the builtin headers available in 
the right place some other way.

Original comment by kim.gras...@gmail.com on 7 Feb 2015 at 8:12

GoogleCodeExporter commented 8 years ago
I'm not sure but I believe that this is a change in llvm/clang, because
with IWYU 0.2/clang 3.4 I had to set up the relative paths to get the tests
to pass, but with 0.3/3.5 the tests pass without the relative paths.

Original comment by davejohansen on 20 Feb 2015 at 4:37

GoogleCodeExporter commented 8 years ago
I've a similar problem. I installed LLVM+Clang some time ago into 
`/opt/llvm/llvm-3.6.0` (a symlink `/opt/llvm/default` exists). Today I 
installed iwyu into `/opt/include-what-you-use/include-what-you-use-clang_3.6` 
(a symlink `/opt/include-what-you-use/default` exists). I am getting the 
following output when running `iwyu_tool.py -p .` in the build directory of my 
project:

    warning: unknown warning option '-Wdouble-promotion'; did you mean '-Wdocumentation'? [-Wunknown-warning-option]
    warning: unknown warning option '-Wlogical-op'; did you mean '-Wlong-long'? [-Wunknown-warning-option]
    In file included from [...]:
    In file included from /usr/include/boost/test/unit_test.hpp:19:
    In file included from /usr/include/boost/test/test_tools.hpp:19:
    In file included from /usr/include/boost/test/predicate_result.hpp:19:
    In file included from /usr/include/boost/test/utils/class_properties.hpp:20:
    In file included from /usr/include/boost/test/detail/config.hpp:19:
    In file included from /usr/include/boost/config.hpp:40:
    In file included from /usr/include/boost/config/select_stdlib_config.hpp:18:
    /usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../include/c++/4.7/cstddef:44:10: fatal error: 'stddef.h' file not found
    #include <stddef.h>

I am using GCC 4.7.1 to compile the project.

Original comment by Florian....@gmail.com on 12 Aug 2015 at 2:31

GoogleCodeExporter commented 8 years ago
Hi there,

Please move this to the GitHub bug tracker;
https://github.com/include-what-you-use/include-what-you-use/issues/100

Google Code is scheduled for shutdown pretty soon.

Thanks,
- Kim

Original comment by kim.gras...@gmail.com on 12 Aug 2015 at 2:41