我想在编译后直接运行构建的程序,这样我就可以用scons
构建和启动我的程序。
我认为这个 SConstruct-File 会在程序重建时启动它。
main = Program( "main", [ "main.cc" ] )
test = Command( None, None, "./main >testoutput" )
Depends( test, main )
每次我运行 scons
main = Program( "main", [ "main.cc" ] )
test = Command( None, None, "./main >testoutput" )
Requires( test, main )
但两者都不行,我的程序从未执行过。我做错了什么?
最佳答案
只有在构建时才运行程序应该会更好。
main = Program( "main", [ "main.cc" ] )
test = Command( target = "testoutput",
source = "./main",
action = "./main > $TARGET" )
Depends( test, main )
并且每次都使用 AlwaysBuild() 来运行它,正如@doublep 所提到的那样:
main = Program( "main", [ "main.cc" ] )
test = Command( target = "testoutput",
source = "./main",
action = "./main > $TARGET" )
AlwaysBuild( test )
如果你想查看测试输出的内容,你可以这样做:
(假设是 Linux。用一些 Python 代码打印文件会更便携)
main = Program( "main", [ "main.cc" ] )
test = Command( target = "testoutput",
source = "./main",
action = ["./main > $TARGET",
"cat $TARGET"] )
AlwaysBuild( test )
关于c++ - scons - 编译后运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070339/