Compilation fails when stdin is read multiple times (original) (raw)

December 3, 2024, 4:51pm 1

If a compilation requires multiple jobs that receive input from stdin, then each job will attempt to read from stdin. This can cause the first job to consume the input from stdin while the other jobs get an empty buffer if they are not in the same process. For example:

echo "int main() { return 0; }" | clang -x c++ - -arch arm64 -arch x86_64

This will first produce an intermediary object file with an empty x86 slice since the input was consumed while generating the arm slice. Then it results in a linker error due to failing to find the main symbol in the empty x86 slice.

I’ve came up with a few ideas, and was wondering if anyone had any thoughts or other ideas:

I know this is likely an uncommon usecase, so I appreciate the input