Search code examples
buildscons

Different target directory for import library building with SCons


I build my shared library:

env.SharedLibrary(target,Split(sources))

Documentation says "On Windows systems, the SharedLibrary builder method will always build an import (.lib) library in addition to the shared (.dll) library, adding a .lib library with the same basename". That is right but I need another directory for it, so my question:

Is it possible to set another target directory for import library? I want .dll and .lib in different directories:

bin/target.dll
lib/target.lib

It is possible to do it in VS projects but I also need a decision for Scons. Thanks.

UPD: We have the following structure

/project
       /bin
       /lib
       /include
       /source
           SConstruct
           /library
             lib.cpp
             SConscript

           /app
              SConscript
              main.cpp

app depends on library.
The following scripts are very simplified.
SConstruct

g_env = Environment()
...
g_target = 'Library_' + g_arch
if g_debug: g_target += 'd'
SConscript('library/SConscript')
SConscript('app/SConscript')

library/SConscript

sources = [ .. ]
env_lib = g_env.Clone()
...
env_lib.SharedLibrary('#../lib/' + g_target,sources)

app/SConscript

sources = [ .. ]
app_env = g_env.Clone()
app_env.Append(LIBPATH = Split('#../lib'))
app_env.Append(LIBS = Split(g_target))
app_env.Program('app',sources)  

If I go to app dir and run

scons -u 

I get all I need:

lib/Library.dll
lib/Library.lib
source/app/app.exe

But if I want just to rebuild Library running
scons -u
from library directory - just builds me .obj files, there is no final shared library.
I have no idea why it works so, I'm not quite familiar with it. But now we need to get final libraries in different directories (.lib in lib, .dll in bin) as I mentioned above.


Solution

  • The standard way of doing this, would be to use the Install() method (see chap 11 "Installing files in other directories" of our UserGuide):

    Install('lib','bin/target.lib')