当我使用 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)构建系统可以做到这一点,我我听说要接受它们)。
最佳答案
你应该使用 output sync option .
关于makefile - 如何解开并行 make -j 编译器消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58792183/