0

Lately I have coded a little bit more with the terminal in Linux to get a deeper understanding of programming. Right now I am trying to automatize the compiling process with the following command:

find . -type f -mmin -1 -name "*.c" | gcc -o output.o -xc -

It basicly should find the latest modified file with ending "*.c" and compile it. However I always get the following error:

<stdin>:1:1: error: expected identifier or ‘(’ before ‘.’ token

Could anybody help me and explain what I am doing wrong or show me an alternative?

Thank you very much and have a nice day!

  • 2
    "I am trying to automatize the compiling process" – You should strongly consider using "make" with a Makefile, or any other similar tool whose job is to manage compilations, rather than coming up with individual hacks. – egmont Aug 24 '18 at 20:08
2

You are piping the name of the file as code to be compiled by gcc

You can pass the name as a file argument instead using xargs:

find . -type f -mmin -1 -name "*.c" | xargs gcc -o output.o -xc

However the "right" tool for this job is really make - which will determine what targets are older than their prerequisites and compile them as required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.