简体   繁体   中英

CPPPATH doesn't seem to work with scons?

while reading the man page of scons, my understanding was, scons doesn't always realize when a header file is changed, cpp source files should also change. I did an experiment, but only to find, whether we have CPPPATH specified or not, seems scons will always detect header file changes and apply rebuild of corresponding source files.

For example, I've got oc file and headers/ directory containing nh file:

#include"headers/n.h"
#include<stdio.h>
int main(){
  printf("hello\n");
  return 2;
}

And my scons SConstruct is like this:

Program('o.c')

When I change the content of nh, scons will rebuild oc file. This is quite surprising to me. I tried to change SConscript like this:

Program('o.c',CPPPATH='.')

This time, I hope scons will only check header files under ".", but not under ./headers. Still, scons will rebuild oc

I moved headers/ to another place above "." directory, and changed oc to include it with absolute path. When I change nh, still scons will rebuild oc

My questions:

(1) How does scons scan and determine if header file has changed, does it call gcc front-end or preprocessor to do this? If so, it seems to be duplicated work with compilation, right?

(2) I don't find specifying CPPPATH useful: whether it's specified, scons will scan. Even when I say CPPPATH=".", scons seems to scan other directories.

Why? Is this by design? If yes, then what's the usage of CPPPATH at all?

Again (see Using 'LIBS' in scons 'Program' command failed to find static library, why? and When I change SConstruct file, scons doesn't trigger rebuild? ) your assumptions are wrong.

SCons simply mimics the usage of CPPPATH as in the gcc/g++ compiler. In your example above, even the gcc will find the header nh without an explicit " -Iheaders " in the command-line. By your explicit

#include"headers/n.h"

it has all the information it needs (full relative/absolute path to the header). Make that a

#include "n.h"

and you will see a difference.

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