Alec Jacobson
Alec Jacobson

Reputation: 6264

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).

Upvotes: 4

Views: 269

Answers (2)

alfC
alfC

Reputation: 16242

Not a killer solution but I do this in scripts:

(make -j 10 || make VERBOSE=1)

What this will do is to compile in parallel and not print much assuming all is good. If that fails a sequential compilation is performed with a verbose output (compilation command line is shown)

This solves two problems, one is that one is not usually interested in the command line of compilations steps that succeed and second (your problem) that all errors are shown at the same time.

Upvotes: 1

MadScientist
MadScientist

Reputation: 100856

You should use the output sync option.

Upvotes: 2

Related Questions