Scons build both a static and a shared library

I am trying to create a static and shared library using the same sources using SCons.

Everything works fine if I just create one or the other, but as soon as I try to build them, only a static library is created.

My SConscript looks like this:

cppflags = SP3_env['CPPFLAGS']
cppflags += ' -fPIC '
SP3_env['CPPFLAGS'] = cppflags

soLibFile = SP3_env.SharedLibrary(
   target = "sp3",
   source = sources)
installedSoFile = SP3_env.Install(SP3_env['SP3_lib_dir'], soLibFile)

libFile = SP3_env.Library(
    target = "sp3",
    source = sources)
installedLibFile = SP3_env.Install(SP3_env['SP3_lib_dir'], libFile)

I also tried SharedObject (sources) before SharedLibrary (passing as a result of returning from SharedObject, not sources), but this is no different. Same thing if I create .a before .so.

How do I get around this?

+5
source share
1 answer

When the installation directory is not at or below the current directory, SCons does not behave as expected, as specified in SCons. Document installation method:

, - "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 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.
+6

All Articles