使用gcc进行递归编译 [英] Recursive compilation using gcc
问题描述
我正在使用 gcc
编译器.
我的项目源代码树看起来像这样
My project source tree looks like somewhat like this
test$~: tree .
.
|-- folder
| |-- hello.cpp
| `-- hello.h
`-- main.cpp
1 directory, 3 files
test$~:
文件 main.cpp
包含 main()
函数以及 main.cpp
调用的所有函数位于名为 folder
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.
一些gcc命令,用于在子目录及其子目录中进行递归编译...等等.此命令应从代码项目的主目录.
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.
推荐答案
由于我目前没有C ++库,因此我无法对其进行真正的测试,但这应该可以:
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++ {} \;
我只是不记得gcc省略了 -o
选项时会发生什么.如果有必要,那么至少可以使您更接近解决方案.我建议尽管改用makefiles
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
这篇关于使用gcc进行递归编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!