我正在尝试构建一个我下载的应用程序,它使用 SCONS“make replacement”和 Fast Light Tool Kit Gui。
检测 fltk 是否存在的 SConstruct 代码是:
guienv = Environment(CPPFLAGS = '')
guiconf = Configure(guienv)
if not guiconf.CheckLibWithHeader('lo', 'lo/lo.h','c'):
print 'Did not find liblo for OSC, exiting!'
Exit(1)
if not guiconf.CheckLibWithHeader('fltk', 'FL/Fl.H','c++'):
print 'Did not find FLTK for the gui, exiting!'
Exit(1)
不幸的是,在我的(Gentoo Linux)系统和许多其他(Linux 发行版)系统上,如果包管理器允许同时安装 FLTK-1 和 FLTK-2,这可能会很麻烦。
我尝试修改 SConstruct 文件以使用 fltk-config --cflags
和 fltk-config --ldflags
(或 fltk-config --libs
code> 可能比 ldflags 更好),像这样添加它们:
guienv.Append(CPPPATH = os.popen('fltk-config --cflags').read())
guienv.Append(LIBPATH = os.popen('fltk-config --ldflags').read())
但这会导致 liblo 测试失败!查看 config.log
显示了它是如何失败的:
scons: Configure: Checking for C library lo...
gcc -o .sconf_temp/conftest_4.o -c "-I/usr/include/fltk-1.1 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT"
gcc: no input files
scons: Configure: no
这到底应该如何完成?
为了完成我的答案,如何从 os.popen( 'command').read() 的结果中删除引号?
编辑这里真正的问题是为什么附加fltk-config
的输出会导致gcc无法接收它应该编译的文件名参数?
I'm trying to build an application I've downloaded which uses the SCONS "make replacement" and the Fast Light Tool Kit Gui.
The SConstruct code to detect the presence of fltk is:
guienv = Environment(CPPFLAGS = '')
guiconf = Configure(guienv)
if not guiconf.CheckLibWithHeader('lo', 'lo/lo.h','c'):
print 'Did not find liblo for OSC, exiting!'
Exit(1)
if not guiconf.CheckLibWithHeader('fltk', 'FL/Fl.H','c++'):
print 'Did not find FLTK for the gui, exiting!'
Exit(1)
Unfortunately, on my (Gentoo Linux) system, and many others (Linux distributions) this can be quite troublesome if the package manager allows the simultaneous install of FLTK-1 and FLTK-2.
I have attempted to modify the SConstruct file to use fltk-config --cflags
and fltk-config --ldflags
(or fltk-config --libs
might be better than ldflags
) by adding them like so:
guienv.Append(CPPPATH = os.popen('fltk-config --cflags').read())
guienv.Append(LIBPATH = os.popen('fltk-config --ldflags').read())
But this causes the test for liblo to fail! Looking in config.log
shows how it failed:
scons: Configure: Checking for C library lo...
gcc -o .sconf_temp/conftest_4.o -c "-I/usr/include/fltk-1.1 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT"
gcc: no input files
scons: Configure: no
How should this really be done?
And to complete my answer, how do I remove the quotes from the result of os.popen( 'command').read()
?
EDIT The real question here is why does appending the output of fltk-config
cause gcc to not receive the filename argument it is supposed to compile?
发布评论
评论(2)
有 2 种类似的方法可以做到这一点:
1)
2)
There are 2 similar ways to do this:
1)
2)
这是一个相当复杂的问题,没有快速的答案
我已经参考了 pkg-config 与 scons 的说明rel="nofollow noreferrer">http://www.scons.org/wiki/UsingPkgConfig。下面的问题也很有帮助
测试 Python 中是否存在可执行文件?。
但我们需要在这些方面更进一步。
因此,经过大量调查后,我发现 os.popen('command').read() 不会修剪尾随换行符 '\n',这正是导致发送到 GCC 的参数被截断的原因。
我们可以使用 str.rstrip() 删除尾随的 '\n'。
其次,正如
config.log
所示,fltk-config
提供的参数,SCONS在将它们提供给GCC之前用双引号括起来。我不太确定具体细节,但这是因为 fltk-config 的输出(通过 os.popen)包含空格字符。我们可以使用诸如 strarray = str.split(" ", str.count(" ")) 之类的东西将输出拆分为出现空格字符的子字符串。
还值得注意的是,我们尝试将 fltk-config --ldflags 附加到 GUI 环境中的错误变量,它们应该已添加到 LINKFLAGS 中。
不幸的是,这只是解决方案的一半。
我们需要做的是:
所以我定义了一些函数来帮助...
1)查找系统上可执行文件的完整路径:
(请参阅:测试Python中是否存在可执行文件?)
1b) 我们还需要测试可执行文件是否存在:
2) 将参数传递给可执行文件并将输出放入数组中:
一些用法:
This is quite a complex problem with no quick answer
I have referred to the instructions for using
pkg-config
with scons at http://www.scons.org/wiki/UsingPkgConfig. The following question is also helpfulTest if executable exists in Python?.
But we need to go a little bit further with these.
So after much investigation I discovered
os.popen('command').read()
does not trim the trailing newline '\n' which is what caused the truncation of the arguments sent to GCC.We can use str.rstrip() to remove the trailing '\n'.
Secondly, as
config.log
shows, the arguments whichfltk-config
provides, SCONS wraps up in double quotes before giving them to GCC. I'm not exactly sure of the specifics but this is because the output offltk-config
(viaos.popen
) contains space characters.We can use something like
strarray = str.split(" ", str.count(" "))
to split the output into substrings where the space characters occur.It is also worth noting that we were attempting to append the
fltk-config --ldflags
to the wrong variable within the GUI environment, they should have been added toLINKFLAGS
.Unfortunately this is only half way to the solution.
What we need to do is:
CPPFLAGS
andLINKFLAGS
.So I have defined some functions to help...
1) Find full path of executable on system:
( see: Test if executable exists in Python? )
1b) We also need to test for executable existence:
2) Pass arguments to executable and place the output into an array:
Some usage: