Alex Alex - 6 months ago 33
C Question

CCCOMSTR/LINKCOMSTR for SharedLibrary in SConscript will not work

I'm pretty new to SCons and noticed that CCCOMSTR and LINKCOMSTR will not work when I'm building a shared library in the SConscript.

Here is the simplified version of my SConstruct:

CFLAGS = ["-Wall", "-pedantic", "-std=c99"]

# building environment
env = Environment(CFLAGS = CFLAGS, CPPDEFINES = ["DEBUG"])

# checking dependencies
conf = env.Configure()
conf.CheckHeader("stdlib.h")
conf.CheckHeader("string.h")
conf.CheckLib("libdl")

env["CCCOMSTR"] = "Compiling $SOURCE ..."
env["LINKCOMSTR"] = "Linking $TARGET ..."

SConscript(dirs = ["lib1", "lib2"], exports=["env", "conf"], name = "SConscript")

# main function
env.Program(target = "prog", LIBS=["libdl"], source = Glob("*.c"))


and the library SConscript would look like:

Import("env", "conf")
env.SharedLibrary(target = "test1", source = Glob("*.c"))


My expectation is that the
env["CCCOMSTR"]
and
env["LINKCOMSTR"]
should be propagated via Import and displayed properly. This however isn't happening and I see a gcc/clang command instead.
Setting these variables in the SConscript does not make any difference either.

The output is as follows:

scons: Reading SConscript files ...
Checking for C header file stdlib.h... (cached) yes
Checking for C header file string.h... (cached) yes
Checking for C library libdl... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
Compiling log.c ...
Compiling main.c ...
clang -o lib1/test1.os -c -Wall -pedantic -std=c99 -g -fPIC -DDEBUG lib1/test1.c
clang -o lib1/libtest1.so -shared lib1/test1.os -ldl
clang -o lib2/test2.os -c -Wall -pedantic -std=c99 -g -fPIC -DDEBUG lib2/test2.c
clang -o lib2/libtest2.so -shared lib2/test2.os -ldl
Compiling xalloc.c ...
Linking prog ...
scons: done building targets.


Is it just a SCons bug or something that I am doing wrong here? Could not find much info about it in the net, hence asking here. :)

(SCONS versions that I've tried and that displayed the behaviour above are v2.1.0, v2.3.4)

Answer Source

After some research I found the answer and now it displays it properly:

...
env["SHCCCOMSTR"]   = "SHCC $SOURCE"
env["SHLINKCOMSTR"] = "SHLINK $TARGET"
env["CCCOMSTR"]     = "CC   $SOURCE"
env["LINKCOMSTR"]   = "LINK $TARGET"
...

I thought I had tried this before and it didn't work, but obviously something was wrong since it works now. So the output is as follows after the change (as expected):

...
CC   log.c
CC   main.c
SHCC lib1/test1.c
SHLINK lib1/libtest1.so
SHCC lib2/test2.c
SHLINK lib2/libtest2.so
CC   util.c
CC   xalloc.c
LINK prog

Oh well - SCons appears to work correctly and in fact rocks!