C ++库的目录结构 [英] Directory structure for a C++ library

查看:71
本文介绍了C ++库的目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++库.最终,我想将其公开提供给多个平台(至少是Linux和Windows)以及一些示例,以及 Python 绑定.工作进展顺利,但目前该项目非常混乱,仅针对 C ++ ,而不是多平台.

I am working on a C++ library. Ultimately, I would like to make it publicly available for multiple platforms (Linux and Windows at least), along with some examples and Python bindings. Work is progressing nicely, but at the moment the project is quite messy, built solely in and for Visual C++ and not multi-platform at all.

因此,我觉得有必要进行清理.我要改进的第一件事是项目的目录结构.我想创建一种适用于 Automake 工具的结构,以允许在多个工具上轻松进行编译平台,但我从未使用过这些平台.由于我仍将在Visual Studio中进行(大部分)编码,因此,我还需要在某个地方保留Visual Studio项目和解决方案文件.

Therefore, I feel a cleanup is in order. The first thing I'd like to improve is the project's directory structure. I'd like to create a structure that is suitable for the Automake tools to allow easy compilation on multiple platforms, but I've never used these before. Since I'll still be doing (most of the) coding in Visual Studio, I'll need somewhere to keep my Visual Studio project and solution files as well.

我尝试用Google搜索诸如"C ++库目录结构"之类的术语,但似乎没什么有用的.我找到了一些非常基本的准则,但没有明确的解决方案.

I tried to google for terms like "C++ library directory structure", but nothing useful seems to come up. I found some very basic guidelines, but no crystal clear solutions.

在查看一些开源库时,我想到了以下内容:

While looking at some open source libraries, I came up with the following:

\mylib
    \mylib <source files, read somewhere to avoid 'src' directory>
        \include? or just mix .cpp and .h
    \bin <compiled examples, where to put the sources?>
    \python <Python bindings stuff>
    \lib <compiled library>
    \projects <VC++ project files, .sln goes in project root?>
    \include? 
    README
    AUTHORS
    ...

我以前在多平台开发/开放源代码项目中没有/只有很少的经验,并且很惊讶我找不到关于如何构建这样的项目的任何好的指导原则.

I have no/little previous experience with multi-platform development/open source projects and am quite amazed that I cannot find any good guidelines on how to structure such a project.

通常应该如何组织这样的图书馆项目?建议阅读什么?有一些很好的例子吗?

How should one generally structure such a library project? What ca be recommended to read? Are there some good examples?

推荐答案

Unix库中非常普遍的一件事是它们的组织方式如下:

One thing that's very common among Unix libraries is that they are organized such that:

./         Makefile and configure scripts.
./src      General sources
./include  Header files that expose the public interface and are to be installed
./lib      Library build directory
./bin      Tools build directory
./tools    Tools sources
./test     Test suites that should be run during a `make test`

它在某种程度上反映了/usr下的传统Unix文件系统,其中:

It somewhat reflects the traditional Unix filesystem under /usr where:

/usr/src      Sometimes contains sources for installed programs
/usr/include  Default include directory
/usr/lib      Standard library install path
/usr/share/projectname   Contains files specific to the project.

当然,它们可能以/usr/local结尾(这是GNU autoconf的默认安装前缀),并且它们可能根本不遵循此结构.

Of course, these may end up in /usr/local (which is the default install prefix for GNU autoconf), and they may not adhere to this structure at all.

没有严格的规定.我个人不是这样组织事情的. (例如,除了最大的项目外,我完全避免使用./src/目录.我也不使用自动工具,而是使用CMake.)

There's no hard-and-fast rule. I personally don't organize things this way. (I avoid using a ./src/ directory at all except for the largest projects, for example. I also don't use autotools, preferring instead CMake.)

我对您的建议是,您应该选择一个对您来说有意义的目录布局(以及您的团队).做最适合您选择的开发环境,构建工具和源代码控制的事情.

My suggestion to you is that you should choose a directory layout that makes sense for you (and your team). Do whatever is most sensible for your chosen development environment, build tools, and source control.

这篇关于C ++库的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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