本文介绍了使用Makefile的更大的C ++项目有什么好的目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用Makefile的大型C ++项目,什么是好的目录结构?

What's a good directory structure for larger C++ projects using Makefile ?

这是我的目录结构看起来的样子:

This is how my directory structure looks at the moment:

lib/ (class implementations *.cpp)
include/ (class definitions *.h)
tests/ (main.cpp for quick tests)

现在,我不知道我的Makefile应该是什么样子...它不似乎工作时.cpp文件和.h文件不在同一目录。任何人都可以指定一个共同的目录结构与一个伴随的Makefile,这样我不会重塑的轮子?

Now, I'm not sure how my Makefile should look like... it doesn't seem to work when .cpp files and .h files aren't in the same directory. Could anyone point me to a common directory structure with an accompanying Makefile so that I don't reinvent the wheel ?

推荐答案

.c文件的.cpp文件并不总是一个很好的解决方案。一般来说,当它被用作一个库(include和private头中的公共头部和源代码)时,我将它们分开。

Separating the .cpp of the .h file is not always a good solution. Generally I separate both of them when it is used as a library (public header in include and private header with the source code).

如果它是一个库,是确定。

If it is a library, this structure is ok.

lib/ (class implementations *.cpp .h)
include/ (class definitions *.h) <- Only those to be installed in your system
tests/ (main.cpp for quick tests)
doc/ (doxygen or any kind of documentation)

如果是应用程序

src/ (source for the application)
lib/ (source for the application library *.cpp *.hpp)
include/ (interface for the library *.h)
tests/ (main.cpp for quick tests) <- use cppunit for this part
doc/ (doxygen or any kind of documentation)

使用标志-I $(PROJECT_BASE)/ include指定编译的包含路径

Use the flag -I$(PROJECT_BASE)/include to specify the include path for the compilation

如果它是一个大项目,使用 autoconf / automake cmake 工具来构建所有内容。这将缓解发展。

If it is a big project, it can be good to use tool like autoconf/automake or cmake to build everything. It will ease the development.

这篇关于使用Makefile的更大的C ++项目有什么好的目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 21:07