當安裝目錄爲或在當前目錄下不,使用SCons並不像預期的那樣,如SCons Install method docs:
注意評論,但是,在安裝文件仍然被認爲是一個類型 文件「build」。當您記住SCons的默認 行爲是在當前目錄中或以下創建文件時,這一點很重要。 如上例所示,如果要在頂級SConstruct文件的目錄樹以外的目錄 中安裝文件,則必須指定 的目錄(或更高的目錄,例如/)爲其安裝任何內容有:
也就是說,您必須調用SCONS並將安裝目錄作爲目標(您的情況爲SP3_env['SP3_lib_dir']
)才能執行安裝。爲了簡化這一點,請按照以下方式使用env.Alias()
。
當您調用SCons時,您至少應該看到靜態庫和共享庫都建立在本地項目目錄中。然而,我想象,SCons不會安裝它們。下面是我在Ubuntu上提出,工作的例子:
env = Environment()
sourceFiles = 'ExampleClass.cc'
sharedLib = env.SharedLibrary(target='example', source=sourceFiles)
staticLib = env.StaticLibrary(target='example', source=sourceFiles)
# Notice that installDir is outside of the local project dir
installDir = '/home/notroot/projects/sandbox'
sharedInstall = env.Install(installDir, sharedLib)
staticInstall = env.Install(installDir, staticLib)
env.Alias('install', installDir)
如果我執行scons的,沒有目標,我得到如下:
# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
scons: done building targets.
然後我可以安裝,執行scons的與安裝目標,如下:
# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.
或者,你可能只是做這一切與一個命令,先清理一切
# scons -c install
然後,做這一切只用一個命令:
# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.