SConscript 中 SharedLibrary 的 CCCOMSTR/LINKCOMSTR 将不起作用 [英] CCCOMSTR/LINKCOMSTR for SharedLibrary in SConscript will not work

查看:62
本文介绍了SConscript 中 SharedLibrary 的 CCCOMSTR/LINKCOMSTR 将不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SCons 非常陌生,并注意到当我在 SConscript 中构建共享库时 CCCOMSTR 和 LINKCOMSTR 将不起作用.

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.

这是我的 SConstruct 的简化版本:

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"))

和库 SConscript 看起来像:

and the library SConscript would look like:

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

我的期望是 env["CCCOMSTR"]env["LINKCOMSTR"] 应该通过导入传播并正确显示.然而,这并没有发生,我看到的是 gcc/clang 命令.在 SConscript 中设置这些变量也没有任何区别.

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.

输出如下:

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.

这只是一个 SCons 错误还是我在这里做错了什么?在网上找不到太多关于它的信息,因此在这里询问.:)

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 版本是 v2.1.0、v2.3.4)

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

推荐答案

经过一番研究,我找到了答案,现在它可以正确显示:

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

哦,好吧 - SCons 似乎工作正常,但实际上非常棒!

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

这篇关于SConscript 中 SharedLibrary 的 CCCOMSTR/LINKCOMSTR 将不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆