Let's say I have a C++ file called
dummy.cpp, and I need to compile it with g++ in such a way that it's being from stdin and g++ spits the compiled binary out to stdout.
If only the stdin part is necessary the following command does the trick:
$ g++ -x c++ -o dummy - < dummy.cpp
Now adding the output part, as far as I know we need to use for example
/proc/self/fd/1) as the output parameter, however it won't work as it exits with a linker error.
$ g++ -x c++ -o /dev/stdout - < dummy.cpp /usr/bin/ld: final link failed: Illegal seek collect2: error: ld returned 1 exit status
If I redirect it from the terminal to a file via
g++ -x c++ -o /dev/stdout - < dummy.cpp > dummy it will work correctly. I guess the problem is that stdout is not seekable and when it gets piped into a file it will "become". But why does ld the file to be seekable and can it be circumvented somehow?