Home > Software design >  Can I find all .c files, compile them and create a static library with them all at once?
Can I find all .c files, compile them and create a static library with them all at once?

Time:10-03

I want to find all my c source files from parent directory, compile them and create a static library with them all at once. I tried this ar -rc libmylib.a < gcc -c < find ../ -type f -name '*.c' but it throws: bash: gcc: No such file or directory.

CodePudding user response:

gcc doesn't print the object file name so you'll have to divide it up into two command lines. Example:

find .. -type f -name '*.c' -exec gcc -c {} \;
ar -rc libmylib.a *.o
  • Related