shell - How can I compile all files in all subdirectories using find? -


i have lots of c++ programs unrelated each other , each 1 being in 1 file. directory structure looks this:

dir1     program1.cpp     program1.h     program2.cpp     program2.h dir2     program3.cpp     program3.h     program4.cpp     program4.h dir3     program5.cpp     program5.h     program6.cpp     program6.h .. 

i'm trying come shell script compile them , give executables different names. have been trying find so:

find . -type f -name *.cpp -exec g++ -llibname '{}' \; 

this compiles files produces a.out each file end 1 executable in end. how can strip file extension , give executable name? (e.g. program1.cpp need g++ program1.cpp -o program1)

you this:

find . -type f -name '*.cpp' -exec sh -c 'g++ {} -o $(basename {} .cpp)' \; 

this put executables in directory launch command from. if you'd rather keep them in same directory source files, should it:

find . -type f -name '*.cpp' -exec sh -c 'g++ {} -o $(dirname {})/$(basename {} .cpp)' \; 

(remember quote filename pattern, otherwise command start breaking if ever have .cpp file in current directory.)


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -