If I do
*.c
it will return a list of files ending with .c
, separated by a space. However, I'd like it to instead return a list of files, prefixed with #include "
and postfixed with "\\n
.
eg output
#include "blah.c"
#include "meh.c"
#include "hehe.c"
I want to pipe the results of this into gcc -xc -
so bonus points if the command is a one-liner.
(And no, I don't want to just cat *.c
because it'll lose source-location information)
Perhaps something like
for f in *.c ; do
printf '#include "%s"\n' $f
done | gcc -xc -
should do what you want
However, gcc
accepts multiple source files, so you could just do
gcc -Wall *.c -o yourprog -lyourlibrary
You could also pass -g -O -flto
to gcc
有一个更简单的方法:
printf '#include "%s"\n' *.c
I didnt test this, but this might do it
for a in *.c ; do echo '#include "'$a'"' ; done | gcc -xc -
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.