Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to untangle parallel make -j compiler messages?

When I use make -j to parallelize compilation commands, (unsurprisingly) any compiler messages (warnings/errors) from concurrent commands get interleaved. I'm wondering if there's a way to untangle these messages.

For example, with make -j I might see something like:

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

Each .cpp triggers a warning but they're interleaved in an arbitrary order. Instead if I issue make, then I get the desired sequential output:

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

but obviously I don't get to take advantage of parallel building.

Is there any way to gather up warnings/errors from each command during the parallel build?

(I'm not super attached to make. If ninja or other cmake-supported command line (non-GUI IDE) build systems can do this, I'm hear to accept them).

like image 629
Alec Jacobson Avatar asked Sep 20 '25 07:09

Alec Jacobson


1 Answers

You should use the output sync option.

like image 151
MadScientist Avatar answered Sep 23 '25 09:09

MadScientist