可移植地编译整个目录
是否有一种干净/可移植的方法可以从给定目录递归下降,将所有找到的 .cpp 文件编译到单个输出文件中?我不确定 makefile 是否能够完成这类事情,或者它是否是某种构建脚本的工作,但我想避免将各种 IDE 的项目文件与我的代码一起维护。
Is there a clean/portable way to descend recursively from a given directory, compiling all found .cpp
files into a single output file? I'm not sure if makefiles are capable of this sort of thing, or if it's a job for some kind of build script, but I'd like to avoid maintaining various IDEs' project files along with my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在这里做不同的事情。我建议您使用多平台构建系统,并遵循它的文档。我过去使用过 CMake,但我不知道如何告诉它编译目录中的所有 文件。
优点是用户可以使用 CMake 为大多数常见 IDE 生成项目文件,因此它允许 VisualStudio 用户生成 VS 解决方案、MacOSX 用户生成 Xcode 项目、几乎任何环境中的 Eclipse CDK 项目、Makefile...
There are different things that you can do here. I would suggest that you use a multiplatform build system, and follow the documentation for it. I have used CMake in the past, but I wouldn't know how to tell it to compile all files in a directory.
The advantage is that the user can use CMake to generate project files for most common IDEs, so it would allow VisualStudio users to generate VS solutions, MacOSX users to generate Xcode projects, Eclipse CDK projects in pretty much any environment, Makefiles...
有 通配符函数,可以是用于匹配这样的模式:
这不是递归的,但至少可以让您不必手动指定某个目录中的文件。构建它们的规则看起来像这样:
哦,回答你的问题,这个方法是完全可移植的。
There's the wildcard function which can be used to match a pattern like so:
This is not recursive, but will at least save you from having to manually specify the files in a certain directory. The rule for building them would look something like this:
Oh, and to answer your question, this method is completely portable.