Scons VariantDir () duplicate CPPPATH and LIBPATH at compilation?

Here is my simple case. I got the original file structure as follows:

.
├── SConstruct
└── src
    ├── SConscript
    ├── staticLib
    │   ├── classInStaticLib.cpp
    │   ├── classInStaticLib.h
    │   └── SConscript
    └── test.cpp

SConstruct:

VariantDir('build', 'src', duplicate=0)
SConscript('build/SConscript')

CSI / SConscript:

import os
lib = 'staticLib'
SConscript(os.path.join(lib, 'SConscript'))
Program( 'test',
         'test.cpp',
         CPPPATH = lib,
         LIBS = lib,
         LIBPATH = lib )

CSI / staticLib / SConscript:

Library('staticLib', 'classInStaticLib.cpp')

After running scons, I got the following command:

g++ -o build/staticLib/classInStaticLib.o -c src/staticLib/classInStaticLib.cpp
ar rc build/staticLib/libstaticLib.a build/staticLib/classInStaticLib.o
ranlib build/staticLib/libstaticLib.a
g++ -o build/test.o -c -Ibuild/staticLib -Isrc/staticLib src/test.cpp
g++ -o build/test build/test.o -Lbuild/staticLib -Lsrc/staticLib -lstaticLib

completed without error. But note that in the 4th line there is both -Ibuild / staticLib and "-Isrc / staticLib", and "-Lbuild / staticLib" and "-Lsrc / staticLib" in the 5th line. There should be only one.

Why is this happening?

+4
source share
4 answers

I think this is because you are using a function SCons VariantDir()that causes SCons to look in the assembly directory. Ive never seen him use source directories and variant_dir.

VariantDir() , SConscript(). SConscript() SConstruct, variant_dir VariantDir(), :

SConscript('src/SConscript', variant_dir='build', duplicate=0)

src/SConscript :

import os
lib = 'staticLib'
SConscript(os.path.join(lib, 'SConscript'),
           variant_dir=os.path.join(lib, 'build'),
           duplicate=0)
Program( 'test',
         'test.cpp',
         CPPPATH = lib,
         LIBS = lib,
         LIBPATH = lib )

, scons, BTW :

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/staticLib/classInStaticLib.o -c src/staticLib/classInStaticLib.cpp
ar rc build/staticLib/libstaticLib.a build/staticLib/classInStaticLib.o
ranlib build/staticLib/libstaticLib.a
g++ -o build/test.o -c -Ibuild/staticLib -Isrc/staticLib src/test.cpp
g++ -o build/test build/test.o -Lbuild/staticLib -Lsrc/staticLib -lstaticLib
scons: done building targets.

$ tree build/
build/
|-- staticLib
|   |-- classInStaticLib.o
|   `-- libstaticLib.a
|-- test
`-- test.o

1 directory, 4 files

, SCons , . variant_dir . , , .

+1

" " VariantDir() , SCons.

. four.pairlist.net/pipermail/scons-users/2014-April/002440.html

Pawel : " /, (, SWIG SConf), dir, , -Ibuild/staticLib -Isrc/staticLib -."

+1

Here is the workaround I used:

import os

def abs_path(rel_path):
    return os.path.join(Dir('.').srcnode().abspath, rel_path)

lib = 'staticLib'
SConscript(os.path.join(lib, 'SConscript'))
Program( 'test',
         'test.cpp',
         CPPPATH = abs_path(lib),
         LIBS = lib,
         LIBPATH = lib )
0
source

I created this directory structure:

stest.cpp
Sconstruct
dira/hello.cpp
dira/hello.h
dirb/hello.cpp
dirb/hello.h

My Sconstruct contains the following:

SOURCES = [ 'stest.cpp', 'hello.cpp' ]
common = Environment ()
a=common.Clone (CPPPATH='#')
a.Repository ('#/dira')
a.Object ('obja/stest.o', 'stest.cpp')
a.Object ('obja/hello.o', 'dira/hello.cpp')
a.Program ('obja/a', ['obja/stest.o', 'obja/hello.o'])
a.Alias ('a', 'obja/a')
b=common.Clone (CPPPATH='#')
b.Repository ('#/dirb')
b.Object ('objb/stest.o', 'stest.cpp')
b.Object ('objb/hello.o', 'dirb/hello.cpp')
b.Program ('objb/b', ['objb/stest.o', 'objb/hello.o'])
b.Alias ('b', 'objb/b')

Running scons -n a bgives the following:

g++ -o obja/stest.o -c -I. -Idira -Idirb obja/stest.cpp
g++ -o obja/hello.o -c -I. -Idira -Idirb obja/hello.cpp
g++ -o obja/a obja/stest.o obja/hello.o
g++ -o objb/stest.o -c -I. -Idira -Idirb objb/stest.cpp
g++ -o objb/hello.o -c -I. -Idira -Idirb objb/hello.cpp
g++ -o objb/b objb/stest.o objb/hello.o

So, this obviously has nothing to do with VariantDir().

-1
source

All Articles