This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Questions on the result of dependency generation
- From: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- To: chran wang <dmmychrnwng at gmail dot com>, gcc-help at gcc dot gnu dot org
- Cc: ryxi at stu dot xidian dot edu dot cn
- Date: Sat, 19 Aug 2017 16:32:32 +0800
- Subject: Re: Questions on the result of dependency generation
- Authentication-results: sourceware.org; auth=none
- References: <CAH4Y+tw3ADTVCVGx1sebO+k_W8+G86ukOExNpWm0xp5VLU6Gew@mail.gmail.com>
On 2017-08-18 15:52 -0700, chran wang wrote:
> Hello,
>
> I observed some weird results about the dependency generation.
>
> Suppose the source code structure is as follows:
>
> root
> |-- c
> | |-- c.cpp
> | |-- c.h
>
> 'c.cpp' includes the header file 'c.h' by
> #include "c/c.h"
>
> Now I try to generate the dependencies for c/c.cpp.
>
> (A) If I'm now in 'root' folder and run command
> g++ -MM -MT c/c.o c/c.cpp
> the compiler outputs
> c/c.o : c/c.cpp # which is wrong because it lacks c/c.h
Your #include directive is bad. The compiler gives:
LANG= g++ -MM -MT c/c.o c/c.cpp
c/c.cpp:1:10: fatal error: c/c.h: No such file or directory
#include "c/c.h"
^~~~~~~
compilation terminated.
> (B) If I'm in folder 'c' and run command
> g++ -MM -MT c.o c.cpp
> the compiler can ouput the correct results
> c.o : c.cpp c.h
Ditto.
> (C) If I'm in the parent folder of folder 'root' and run command
> g++ -I./root -MM -MT root/c/c.o root/c/c.cpp
> the results is also correct:
> root/c/c,o : root/c/c.cpp root/c/c.h
With -I./root the include directive is correct.
> (D) Now, if I'm in folder 'root' again and include the head file 'c.h'
> for 'c.cpp' by
> #include "c.h" instead of #include "c/c.h"
> the result is also correct.
Ditto.
> I'm wondering why (A) cannot give a correct dependency output but (B),
> (C) and (D) can.
Which version of GCC are you using? It seems like a preprocessor bug
and I can't reproduce it with GCC 4.6, 4.7, 5.x, 6.x and 7.x.
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University