【发布时间】:2019-11-10 19:28:28
【问题描述】:
当我使用make -j 并行化编译命令时,(不出所料)来自并发命令的任何编译器消息(警告/错误)都会交错。我想知道是否有办法解开这些消息。
例如,make -j 我可能会看到类似的内容:
Scanning dependencies of target test
[ 33%] Building CXX object CMakeFiles/test.dir/C.cpp.o
[ 33%] Building CXX object CMakeFiles/test.dir/B.cpp.o
[ 50%] Building CXX object CMakeFiles/test.dir/A.cpp.o
[ 66%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[ 83%] Building CXX object CMakeFiles/test.dir/D.cpp.o
/tmp/B.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
/tmp/C.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
1 warning generated.
/tmp/A.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
/tmp/D.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[100%] Linking CXX executable test
[100%] Built target test
每个.cpp 都会触发一个警告,但它们会以任意顺序交错。相反,如果我发出make,那么我会得到所需的顺序输出:
make
[ 16%] Building CXX object CMakeFiles/test.dir/A.cpp.o
/tmp/A.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[ 33%] Building CXX object CMakeFiles/test.dir/B.cpp.o
/tmp/B.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[ 50%] Building CXX object CMakeFiles/test.dir/C.cpp.o
/tmp/C.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[ 66%] Building CXX object CMakeFiles/test.dir/D.cpp.o
/tmp/D.cpp:3:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
[ 83%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[100%] Linking CXX executable test
[100%] Built target test
但显然我无法利用并行构建。
有没有办法在并行构建期间收集来自每个命令的警告/错误?
(我对make 没有超级依赖。如果ninja 或其他支持cmake 的命令行(非GUI IDE)构建系统可以做到这一点,我听说接受它们)。
【问题讨论】:
标签: makefile cmake stdout stderr build-system