This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Questions on the result of dependency generation


Hello Ruoyao,

For (B), I'm sorry that I forgot to say that I changed '#include
"c/c.h" ' to '#include "c.h" ' in that case. For others, I did not
encounter any errors on my machine as you showed.

I'm using ubuntu 16.04. At first, I tried with g++ 5.4.0 since it is
shipped with ubuntu. Then I compiled a gcc 7.1 from its source code. I
got the same result under g++ 7.1 (and no error output).



On Sat, Aug 19, 2017 at 1:32 AM, Xi Ruoyao <ryxi@stu.xidian.edu.cn> wrote:
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]