I see several problem in your approach:
find
should not be used in a loop, but rather with a -fprint <file>
. So in your case:
find . -name "*.o" -type f -fprintf myfiles
Secondly, redirecting your file to gcc
stdin will not work as you think, as it uses the input as the source of the code: see this question. What you want instead is to expand the list of objects to a list of arguments:
cat myfiles | xargs gcc -o myFile
xargs
does it nicely. But as @n.m. mentioned, you could do everything at once with a command substitution:
gcc -o myfile $(find . -type f -name *.o -print0)
The only difference I suggest is to use a -print0
so that find put a \0
at the end of a find instead of a \n
.
Good Luck