scons:从外部命令行添加额外的标志会导致编译错误

时间:2017-07-12 13:50:53

标签: c++ file object scons

我有一个名为testlibxml2.cpp的libxml2测试文件。我试着编译它希望scons像这样:

import os
env=Environment(ENV=os.environ)

cflags=os.popen("xml2-config --cflags").read()
lflags=os.popen("xml2-config --libs").read()
env.Program(target='testlibxml2', 
source='testlibxml2.cpp',CCFLAGS=cflags, LIBS=lflags)

编译有错误,因为g ++命令缺少源文件名,并且没有完成任何链接:

g++ -o cpp/build/testlibxml2.o -c -I/usr/include/libxml2

clang: error: no input files

然后我尝试使用Object文件作为中间步骤来修复它:

cflags=os.popen("xml2-config --cflags").read()
lflags=os.popen("xml2-config --libs").read()
env.Append(CCFLAGS=cflags)
obj=Object('testlibxml2.cpp',CCFLAGS=cflags)
env.Program(target='testlibxml2', source=obj,CCFLAGS=cflags, LIBS=lflags)

仍然失败并出现错误:

g++ -o cpp/build/testlibxml2.o -c -I/usr/include/libxml2

clang:错误:没有输入文件

为什么scons的行为如此奇怪:

  

使用外部命令输出时无法填充源文件名

     

之后无法提供链接步骤。

如何解决?

谢谢,有两种解决方法:

cflags=os.popen("xml2-config --cflags").read()
lflags=os.popen("xml2-config --exec-prefix=/usr --libs").read()
env.Append(CCFLAGS=cflags)
env.Append(LINKFLAGS=lflags)

另一个是:

env.ParseConfig("xml2-config --cflags --exec-prefix=/usr --libs")

0 个答案:

没有答案