c++ - scons - 编译后运行程序

标签 c++ python scons

我想在编译后直接运行构建的程序,这样我就可以用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/

相关文章:

c++ - C/C++ - 如何管理视频游戏中的循环?

c++ - 使用 LD_PRELOAD 和 dlsym() 覆盖 'free' 或 'delete'

java - 第一次使用 boolean c++ 或 java

python - 嘈杂图像中的圆圈检测

python - 将 excel 的值作为 python 字典检索

c++ - 如何查看 SCons 中将构建哪些目标?

python - 为什么 SCons VariantDir() 不将输出放在给定目录中?

c++ - C++中c_str()的线程安全

python - 如何使这个 Flask-mysql 插入提交?

ubuntu - Scons 找不到 git 和编译器