问题
I am using the gcc
compiler.
My project source tree looks like somewhat like this
test$~: tree .
.
|-- folder
| |-- hello.cpp
| `-- hello.h
`-- main.cpp
1 directory, 3 files
test$~:
The file main.cpp
contains the main()
function and all the functions invoked by main.cpp
lie in the directory named folder
So far in all my little projects I never had to put some source code under a sub-directory.
What I am looking for, in short, is some gcc command for recursive compilation in sub-directories and their subdirectories and so on... This command should be invoked from the home directory of the code project.
回答1:
I couldn't really test it on a c++ library as I don't have one currently, but this should work:
find . -type f -iname *.cpp -execdir g++ {} \;
I just don't remember what happens when the -o
option is omitted for gcc. If its necessary then this will at least bring a you a bit closer to a solution. I would recommend using makefiles instead though
来源:https://stackoverflow.com/questions/9764011/recursive-compilation-using-gcc