scons 在构建中生成不正确的包含路径指令

发布于 2024-12-12 20:29:29 字数 1615 浏览 0 评论 0原文

我使用简单的通用目录设置构建了 scons:

project/
    SConstruct
    src/
        file.cpp
        SConscript
    include/
        namespace/
            header.h

在 file.cpp 中,我通过 #include "namespace/header.h" 包含 header.h,所以我要做的就是简单地将包含目录添加到包含中路径列表。从源(和 SConscript)的角度来看,该路径是“../include”,但构建命令始终具有无效的包含路径。我在 SConscript 中尝试了以下方法:

env.Append(CPPPATH = ["#include"])
env.Append(CPPPATH = [Dir("include")])
env.Append(CPPPATH = [os.getcwd() + os.sep + ".." + os.sep + "include"])
env.Append(CPPPATH = ["../include"])
env.Append(CPPPATH = ["#../include"])

似乎都不起作用。前四个给出“-Iinclude”,而最后一个将包含放在项目上方的目录级别!这是完整的 SConscript

env = Environment()
import os

target_name = "device"

source_files = Split("""
file.cpp
""")

env.Append(CPPPATH = ["#include", os.environ.get("SYSTEMC_PATH"),
    os.environ.get("SYSTEMC_TLM_PATH"), os.environ.get("BOOST_PATH")])

object_list = env.SharedObject(source = source_files)
targetobj = env.SharedLibrary(target = target_name, source = object_list )
Default(targetobj)

并且 SConstruct 只是:

import sys

SConscript('src/SConscript', variant_dir='Release-'+sys.platform, duplicate=0, exports={'MODE':'release'})
SConscript('src/SConscript', variant_dir='Debug-'+sys.platform, duplicate=0, exports={'MODE':'debug'})

我从 SConstruct 所在的目录(即顶级目录)运行 scons。

我做了一些查找,根据 scons doco, # 应该告诉 scons 从 SConscript 的当前目录(即 src 目录)生成路径 - 我假设这是而不是 SConstruct 目录???此外,我看不到任何关于这个特定问题的问题(在这个网站上或一般通过谷歌),通常我只是打人们要求 scons 脚本来完成我已经得到的设置(这是将“include”添加到 CPPPATH)。

对于哪里出了问题有什么想法吗?

I've got a scons build using a simple, common directory setup:

project/
    SConstruct
    src/
        file.cpp
        SConscript
    include/
        namespace/
            header.h

In file.cpp, I include header.h via #include "namespace/header.h" so what I want to do is simply add the include directory to the include path list. From the source (and SConscript) point of view, that path is "../include" but the build command always has an invalid path for the include in it. I've tried the following in the SConscript:

env.Append(CPPPATH = ["#include"])
env.Append(CPPPATH = [Dir("include")])
env.Append(CPPPATH = [os.getcwd() + os.sep + ".." + os.sep + "include"])
env.Append(CPPPATH = ["../include"])
env.Append(CPPPATH = ["#../include"])

none of which seem to work. The first four give "-Iinclude" while the last puts the include at the directory level above project! Here's the full SConscript

env = Environment()
import os

target_name = "device"

source_files = Split("""
file.cpp
""")

env.Append(CPPPATH = ["#include", os.environ.get("SYSTEMC_PATH"),
    os.environ.get("SYSTEMC_TLM_PATH"), os.environ.get("BOOST_PATH")])

object_list = env.SharedObject(source = source_files)
targetobj = env.SharedLibrary(target = target_name, source = object_list )
Default(targetobj)

And the SConstruct is just:

import sys

SConscript('src/SConscript', variant_dir='Release-'+sys.platform, duplicate=0, exports={'MODE':'release'})
SConscript('src/SConscript', variant_dir='Debug-'+sys.platform, duplicate=0, exports={'MODE':'debug'})

I'm running scons from the directory where the SConstruct is located (i.e. the top level directory).

I've done some looking and according to the scons doco, the # is supposed to tell scons to generate the path from the current directory of the SConscript (which is the src directory) - I'm assuming this is instead of the SConstruct directory??? Further, I can't see any questions out there about this particular problem (on this site or via Google in general), usually I'm just hitting people asking for scons scripts for exactly the setup I've got already (which is to add "include" to the CPPPATH).

Any thoughts on where this is going awry?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新雨望断虹 2024-12-19 20:29:29

'#' 相对于顶级 SConstruct,根据 SCons 手册 http: //scons.org/doc/HTML/scons-user/x3240.html

当我重新创建您指定的树时,您在上面提供的脚本会成功构建。这是工作输出:

scons: Reading SConscript files ...
scons: done reading SConscript files. 
scons: Building targets ... 
g++ -o Release-cygwin/file.os -c -Iinclude src/file.cpp 
g++ -o Release-cygwin/device.dll -shared Release-cygwin/file.os 
g++ -o Debug-cygwin/file.os -c -Iinclude src/file.cpp 
g++ -o Debug-cygwin/device.dll -shared Debug-cygwin/file.os 
scons: done building targets.

'#' is relative to the top-level SConstruct, as per the SCons manual http://scons.org/doc/HTML/scons-user/x3240.html

The scripts you provide above build successfully when I recreate the tree you specify. Here's the working output:

scons: Reading SConscript files ...
scons: done reading SConscript files. 
scons: Building targets ... 
g++ -o Release-cygwin/file.os -c -Iinclude src/file.cpp 
g++ -o Release-cygwin/device.dll -shared Release-cygwin/file.os 
g++ -o Debug-cygwin/file.os -c -Iinclude src/file.cpp 
g++ -o Debug-cygwin/device.dll -shared Debug-cygwin/file.os 
scons: done building targets.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文