我在/home/username/local/include下安装了boost。我想用CPPPATH下的这个集合编译一个库。
结构:

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

库.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
对一个程序做同样的事情就行了。
结构:
env = Environment(CPPPATH = '/home/username/local/include')
env.Program('program.cpp')

程序.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.

最佳答案

我不能在我的系统上复制你的错误。你所有的东西在我看来都是对的。
我创建了一个伪造的boost-include设置,并使用了不同的文件名,这样它就不会意外地进入/usr中的真正boost-include。我用的是SCons 2.0.1。

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

库.cpp:
#include <boost/not_a_boost_header.hpp>

void foo() { }

程序.cpp:
#include <boost/not_a_boost_header.hpp>

int main() { return 0; }

结构:
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输出吗?

关于c++ - SCons:如何使库使用CPPPATH选项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8508298/

10-12 22:40