GCC Compiler: Compile several files with different output file names

advertisements

Is it possible to compile multiple files and save the output for each files with different name ? I had only copied .cpp files from old computer to my new one.Those programs are all error free and are tested.So now i have to compile each files to get the output file.There are about 310 programs so it is really hard to compile each file separately.I usually save output file with the same file name without any extension.Is there any way to compile all files in the directory and save each files output separately. I'm looking forward for a command like this

gcc *.cpp -o *

If there are files,

filename1.cpp

filename2.cpp etc.

I want to get the output files like this :

filename1

filename2 etc.

EDIT :

Is there any way to save the timestamp of .cpp file to the output file .??


If each file should have it's own executable and they're all in the same directory you can do this:

for i in *.cpp; do g++ $i -o `basename $i .cpp`; done

To add the timestamp:

for i in *.cpp; do g++ $i -std=c++11 -o `basename $i .cpp`-`date +%Y%m%d -r $i`; done

This will produce the date in YYYYMMDD format after the filename and hyphen

To change modification date:

for i in *.cpp; do g++ $i -std=c++11 -o `basename $i .cpp`; touch -t `date +%Y%m%d%H%M -r $i` `basename $i .cpp`; done