Directory structure for a C++ library

后端 未结 5 696
独厮守ぢ
独厮守ぢ 2020-12-12 09:25

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 Pytho

5条回答
  •  长情又很酷
    2020-12-12 10:01

    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`
    

    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.
    

    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.

    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.

提交回复
热议问题