SCons:如何使库获取CPPPATH选项

时间:2011-12-14 16:48:35

标签: c++ linux scons

我在/home/username/local/include下安装了升级版。我想在CPPPATH下用这个集合编译一个库。

SConstruct:

env = Environment(CPPPATH = '/home/username/local/include')
env.Library('MyLib', 'library.cpp')

library.cpp:

#include <boost/shared_ptr.hpp> // library.cpp:1:32: error: boost/shared_ptr.hpp: No such file or directory

void foo() { }

但是,当我运行scons时,会出现错误error: boost/shared_ptr.hpp: No such file or directory

为程序做同样的事情就可以了。

SConstruct:

env = Environment(CPPPATH = '/home/username/local/include')
env.Program('program.cpp')

program.cpp:

#include <boost/shared_ptr.hpp> // works

int main() { return 0; }

我在这里缺少什么?

修改

这是输出:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o library.o -c -I/home/m/local/include library.cpp
library.cpp:1:32: error: boost/shared_ptr.hpp: No such file or directory
scons: *** [library.o] Error 1
scons: building terminated because of errors.

1 个答案:

答案 0 :(得分:1)

我无法在我的系统上重现您的错误。那里的一切看起来都对我不错。

我创建了一个伪造的提升包含设置,并使用了不同的文件名,因此它不会意外地进入我的真实提升包括/ usr。我正在使用SCons 2.0.1。

$ find /home/acm/local/include -type f
/home/acm/local/include/boost/not_a_boost_header.hpp

library.cpp:

#include <boost/not_a_boost_header.hpp> 

void foo() { }

program.cpp:

#include <boost/not_a_boost_header.hpp> 

int main() { return 0; }

SConstruct:

env1 = Environment(CPPPATH = '/home/acm/local/include')
env1.Library('MyLib', 'library.cpp')

env2 = Environment(CPPPATH = '/home/acm/local/include')
env2.Program('program.cpp')

构建结果:

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o library.o -c -I/home/acm/local/include library.cpp
ar rc libMyLib.a library.o
ranlib libMyLib.a
g++ -o program.o -c -I/home/acm/local/include program.cpp
g++ -o program program.o
scons: done building targets.

你可以发布完整的SCons输出吗?