简体   繁体   中英

gcc auto dependency full path

I have a simple project - it has a foo.cxx and a bar.h :

// bar.h
// nothing

// foo.cxx
#include "bar.h"
// nothing else

If I include bar.h with "" s, then the dependency file has everything with its full paths:

$ g++ -std=c++11 -MP -MMD -MF /home/barry/sandbox/foo.d 
      -c /home/barry/sandbox/foo.cxx -o /home/barry/sandbox/foo.o

$ cat foo.d
/home/barry/sandbox/foo.o: /home/barry/sandbox/foo.cxx \
 /home/barry/sandbox/bar.h

/home/barry/sandbox/bar.h:

However, if I include it with <> s and add -I. , I just get bar.h by itself:

$ g++ -std=c++11 -I. -MP -MMD -MF /home/barry/sandbox/foo.d 
      -c /home/barry/sandbox/foo.cxx -o /home/barry/sandbox/foo.o

$ cat foo.d
/home/barry/sandbox/foo.o: /home/barry/sandbox/foo.cxx bar.h

bar.h:

Is there a way to get the full paths for all of the files?

The issue is with -I. When gcc is determining the include for <bar.h> , it will find it as ./bar.h , and so it will get printed in the dependency file in that same way.

If I were to provide the full path via -I as well:

$ g++ -std=c++11 -I/home/barry/sandbox -MP -MMD 
      -MF /home/barry/sandbox/foo.d 
      -c /home/barry/sandbox/foo.cxx 
      -o /home/barry/sandbox/foo.o

Then regardless of "" or <> , I get the full path of bar.h in foo.d , as desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM