English 中文(简体)
源构建中的 SCons, 仅对可执行程序有效, 不对对象文件有效
原标题:SCons out of source build only works for executable program, not for object files
  • 时间:2012-05-24 08:49:37
  •  标签:
  • c++
  • scons

我配置了以下卫星:

current_directory
|-<.cpp files>
|-<.h files>
|-SConstruct
|-SConscript
|-bin
  |-<empty>

我要构建我的源文件,并将可执行文件及对象文件放入 bin 目录。

这是我在我的 SCcompruilct 文件里有的内容 :

SConscript( SConscript , variant_dir= bin , duplicate=0)

SConsript 文件中,我有:

debug_environment.Program(target =  SsaTest , src_files, LIBS=libraries, LIBPATH=libraries_path)

当我使用 scons 命令构建时,我在 SsaTest 目录中(按要求)获得可执行的 SsaTest ,但对象文件仍留在当前目录中。

如何将 .o 文件建在 >bin 目录中?

非常感谢。

EDIT: 完整 Scontruit file (为 xxxx s原谅我)

import os

# This is correctly Exported()
Import( debug_flags )

# Paths to header files
headers_paths = [ #/../../xxx/include/ ,
                  #/../../../xxx/include/ ,
                  #/../../xxx/include/ ,
                  #/../../xxx/include/ ,
                  #/../../xxx/include/ ]

# Path to source files
src_folder =  #./ 

# Source files list
src_files = [ xxx.cpp ,
              xxx.cpp ,
              xxx.cpp ,
              xxx.cpp ,
              xxx.cpp ]

# Prepend the relative path to each source file name
src_files = [src_folder + filename for filename in src_files]

libraries = [ xxx ,  xxx ,  xxx ,  xxx ,  xxx ,  xxx ,  xxx ,  xxx ]

libraries_path = [ #/../../xxx/lib ,
                   #/../../../xxx/bin , 
                   #/../lib , 
                   #/../../xxx/lib , 
                   #/../../xxx/lib , 
                   #/../../xxx/lib ]

# Debug environment
debug_environment = Environment(CC =  g++ , CCFLAGS=debug_flags, ENV = os.environ, CPPPATH=headers_paths); 
# Executable build command
debug_environment.Program(target =  SsaTest , src_files, LIBS=libraries, LIBPATH=libraries_path)
最佳回答

# 使用不推荐的源文件, 因为有您的情况, scons 无法正确处理变量 dirs, 以及结果如何在来源所在的目录中创建对象文件 。

所以,我试图用同样的配置来构建你的榜样, 并且没有麻烦:

#SConsctruct
SConscript( SConscript , variant_dir= bin , duplicate=0)

#SConscript
src_files = Glob( *.cpp )
debug_environment = Environment()
debug_environment.Program( SsaTest , src_files)

因此,所有对象文件都在文件夹目录中生成 。

Finally, you have no troubles with relation dirs with sources files then using variant dirs. But include dirs are depended from variant dirs. Configuration for example :

build
app
--SConscript
--src
----*.h
----*.cpp
SConstruct

#SConstruct
rootEnv = Environment()
Export( rootEnv )
SConscript( app/SConscript , variant_dir= build , duplicate=0)

你们的士兵会看起来像它:

Import( rootEnv )
env = rootEnv.Clone()
env.Append(CPPPATH = [ #app/src ])
env.Program( app , Glob( src/*.cpp ))

# app/ src - 在使用变式 dir 时, # 非常重要, 因为如果是 ap/ src, 构建命令将会看到 : - Ibuilding/ app/ src (在包含路径之前添加变式 dir ) 。 但是添加 # 命令将会正确看到 : - Iap/ src 。

问题回答

在您的标准定义中插入的一件事是,您是如何用 < code_ / 预览每个源文件路径的 。

# Path to source files
src_folder =  #./ 

您为什么在这条路径中使用点, 不需要它? 尝试使用下面的 < code_ / , 就像您对其它路径所做的那样, 比如 :

# Path to source files
src_folder =  #/ 

另一个选项是将源文件和相应的描述符号放在自己的子目录中。它并不清楚为什么您将一个构建、描述和源文件全部放在一个目录中。要么创建子目录,要么考虑删除该符号,如果不需要的话。

在 Scommunit () 函数中, SCstruct 中的调用, 将变体目录称为 #bin 而不是“ bin ” 。 不确定这是否有用, 但做法更好 。

在使用存储库 () 功能来引用 < a href=" https://stackoverflow.com/q/102009961/115895><这里 所提到的源文件之前,我见过这种行为。

此外,这是非专题的,但如果您的包含路径和图书馆路径(标题路径和库路径变量)不在项目目录结构之外, 您可以考虑使用绝对路径, 而不是使用绝对路径。 就我个人而言, 使用多个 < code>./ 路径的相对路径相当难看。 / 路径 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签