如何编译目录中的所有cpp文件? [英] How can you compile all cpp files in a directory?

查看:146
本文介绍了如何编译目录中的所有cpp文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多文件夹中都有许多源文件.是否有一种方法可以一次性编译所有文件而不必命名它们?

I have a number of source files in a number of folders.. Is there a way to just compile all of them in one go without having to name them?

我知道我可以说

g++ -o out *.cpp 

但是当我尝试

g++ -o out *.cpp folder/*.cpp

我得到一个错误.

执行此操作的正确方法是什么?我知道可以使用makefiles,但是可以用纯正的g ++做到吗?

What's the correct way to do this? I know it's possible with makefiles, but can it be done with just straight g++?

推荐答案

通过指定folder/*.cpp,您可以告诉g ++编译folder中的cpp文件.没错.

By specifying folder/*.cpp you are telling g++ to compile cpp files in folder. That is correct.

您可能缺少的是告诉g ++这些cpp文件#include在哪里可以找到其他文件.

What you may be missing is telling the g++ where to locate additional files that those cpp files #include.

要执行此操作,请告诉您的编译器也使用-I将该目录也include如此:

To do this, tell your compiler to also include that directory with -I like this:

g++ -o out -I ./folder *.cpp folder/*.cpp

在某些情况下,我让编译器忘记了根目录/当前目录中的内容,因此我将其与另一个-I一起手动指定给当前目录.

In some circumstances I have had the compiler forget what was in the root/current directory, so I manually specified it with another -I to the current directory .

g++ -o out -I . -I ./folder *.cpp folder/*.cpp

这篇关于如何编译目录中的所有cpp文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆