I am trying to link a static library [1] into another static library [2] with scons.
Unfortunately the emitted call to "ar" never contains any path to library [1].
According to this post How to merge two "ar" static libraries into one it should be possible to merge to archives into one.
Is the usual call to CheckLibWithHeader not sufficient here?
Best regards
Have you tried specifying the complete path to library [1] when referring to it with the SCons ar command?
Brady
Adding more info to my original answer: Since you havent posted your SCons scripts, I'll assume its something like the one I present below:
Normally, the LIBPATH construction variable is used to specify paths to libraries, but that appears to only work with the Program() builder and is not used with the ar command. What needs to be done then is to specify the complete path for the library in question. Assuming I have the following directory structure:
# tree .
.
|-- SConstruct
|-- fileA.cc
|-- fileA.o
|-- libB
| `-- libmoduleB.a
|-- libmoduleA.a
`-- libmoduleC.a
Here is the SConscript that shows how to do so:
env = Environment()
env.Library(target = 'moduleA', source = 'fileA.cc')
env.Library(target = 'moduleC', source = ['libmoduleA.a', '#libB/libmoduleB.a'])
Or Instead of the relative dir '#libB', you could specify an absolute path. (the '#' in a path means its relative to the SConscript)
And, to make it portable, you should specify the moduleB library (and moduleA) like this:
libBname = "%smoduleB%s" % (env['LIBPREFIX'], env['LIBSUFFIX'])
libB = os.path.join(pathToLibB, libBname)
Here is the result:
# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o fileA.o -c fileA.cc
ar rc libmoduleA.a fileA.o
ranlib libmoduleA.a
ar rc libmoduleC.a libmoduleA.a libB/libmoduleB.a
ranlib libmoduleC.a
scons: done building targets.