Recursive compilation using gcc

瘦欲@ 提交于 2020-01-16 05:20:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!