简体   繁体   English

CPPPATH似乎不适用于scons吗?

[英]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. 在阅读scons的手册页时,我的理解是,当头文件更改时,scons并不总是意识到,cpp源文件也应更改。 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. 我做了一个实验,但是只是发现,无论是否指定了CPPPATH,似乎cons总是会检测头文件的更改并应用相应源文件的重建。

For example, I've got oc file and headers/ directory containing nh file: 例如,我有oc文件和包含nh文件的headers /目录:

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

And my scons SConstruct is like this: 我的骗局SConstruct是这样的:

Program('o.c')

When I change the content of nh, scons will rebuild oc file. 当我更改nh的内容时,scons将重建oc文件。 This is quite surprising to me. 这让我感到非常惊讶。 I tried to change SConscript like this: 我试图像这样更改SConscript:

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

This time, I hope scons will only check header files under ".", but not under ./headers. 这次,我希望scons仅检查“。”下的头文件,而不检查./header下的头文件。 Still, scons will rebuild oc 不过,scons将重建oc

I moved headers/ to another place above "." 我将标题/移动到了“。”上方的另一个位置。 directory, and changed oc to include it with absolute path. 目录,并将oc更改为包含绝对路径。 When I change nh, still scons will rebuild oc 当我更改nh时,scons仍会重建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? (1)scons如何扫描并确定头文件是否已更改,它是调用gcc前端还是预处理器来执行此操作? 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. (2)我发现指定CPPPATH并不是有用的:无论是否指定,scons都会扫描。 Even when I say CPPPATH=".", scons seems to scan other directories. 即使我说CPPPATH =“。”,scons似乎也会扫描其他目录。

Why? 为什么? Is this by design? 这是设计使然吗? If yes, then what's the usage of CPPPATH at all? 如果是,那么CPPPATH的用途是什么?

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中使用“ LIBS”,“ Program”命令无法找到静态库,为什么?并且当我更改SConstruct文件时,scons不会触发重建吗? )您的假设是错误的。

SCons simply mimics the usage of CPPPATH as in the gcc/g++ compiler. SCons只是像在gcc/g++编译器中一样模仿CPPPATH的用法。 In your example above, even the gcc will find the header nh without an explicit " -Iheaders " in the command-line. 在上面的示例中,即使gcc也会在命令行中找到标头nh而没有显式的“ -Iheaders ”。 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. 您会发现有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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