c++ - Scons 没有按照我指定的那样计算正确的 'ParseDepends' 或 'Ignore'

标签 c++ linux parsing dependencies scons

我想告诉scons,当我更改了一个头文件时,不要重新编译我的源文件(这只是我的测试!) 我有 hello.c 文件:

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

我的 SConstruct 文件是:

obj=Object('hello.c')
SideEffect('hello.d',obj)
ParseDepends('hello.d')
Program('hello',obj)

你看,我没有定义任何“FOO”,所以 hello.c 文件根本不使用我的 .h 文件。 我还希望 ParseDepends 能够读取 C 预处理器命令以忽略我的#include“n.h”,因为没有定义“FOO”。

但是当运行scons,然后修改n.h文件,再次运行scons会触发hello.c的rebuild

然后我尝试使用“忽略”语句如下:

hello_obj=Object('hello.c')
hello=Program(hello_obj)
Ignore(hello_obj,'n.h')

好吧,我得到了相同的测试结果:n.h 内的变化不会被 scons 忽略! 为什么?

最佳答案

使用Ignore()。引用 its documentation ,

Sometimes it makes sense to not rebuild a program, even if a dependency file changes. In this case, you would tell SCons specifically to ignore a dependency

在您的情况下,这是一个完整的 SConstruct(我将您的 C 程序更改为 #include "headers/n.h"):

obj=Object('hello.c')
Ignore(obj, 'headers/n.h')
Program('hello',obj)

这是一个证明它有效的 shell session :

$ scons -Q -c
Removed hello.o
Removed hello
$ scons -Q 
gcc -o hello.o -c hello.c
gcc -o hello hello.o
$ echo hello >> headers/n.h 
$ scons -Q 
scons: `.' is up to date.

关于c++ - Scons 没有按照我指定的那样计算正确的 'ParseDepends' 或 'Ignore',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39856347/

相关文章:

c++ - .dll 、 .lib 、 .h 文件有什么区别?

c++定义继承方案

c++ - 如何更改其他类而非主窗口类中的应用程序大小?

matlab - inputParser 验证参数未按预期运行

c++ - 我可以从 C++ 库中包含/导入单个函数吗

linux - 列出文件及其基目录

java - 无法使用 java 命令运行 Pig jar

c - 如何检查这是目录路径还是任何文件名路径?

javascript - 具有两个参数的 Angular 函数具有错误 : [$parse:syntax]

java - 将 JSON 文件转换为字符串