Visual Studio 2008下的C ++项目结构

时间:2022-09-01 19:16:27

So, I've been doing Java for a number of years now, but now I'm starting a C++ project. I'm trying to determine best practices for setting up said project.

所以,我已经做了很多年的Java,但现在我正在开始一个C ++项目。我正在尝试确定设置该项目的最佳实践。

Within the project, how do you generally structure their code? Do you do it Java style with namespace folders and break up your source that way? Do you keep your public headers in an include directory for easy referencing?

在项目中,您通常如何构建代码?你是否使用命名空间文件夹来创建Java样式并以这种方式分解你的源代码?您是否将公共标题保存在include目录中以便于引用?

I've seen both and other ways mentioned, but what's a good method for a large project?

我已经看到了提及的两种方式,但对于大型项目来说,什么是好方法?

Also, how do you deal with resources/folders in your application structure? It's all well and good for the final project to install with a log folder for storing logs, maybe a lib folder for library files, maybe a data folder for data, but how do you manage those bits within the project? Is there a way to define that so when you build the solution it constructs the structure for you? Or, do you simply have to go into your built configuration folders (Debug, Release, etc.), and construct the file structure manually, thus ensuring paths your EXE file is expecting to find are properly positioned?

另外,您如何处理应用程序结构中的资源/文件夹?对于最终项目安装日志文件夹来存储日志,可能是库文件的lib文件夹,也许是数据的数据文件夹,但是如何管理项目中的这些位,这一切都很好!有没有办法定义,所以当你构建解决方案时,它为你构建结构?或者,您是否只需要进入构建的配置文件夹(调试,发布等),并手动构建文件结构,从而确保您的EXE文件期望找到的路径是否正确定位?

2 个解决方案

#1


1  

We tend to make each component a solution, containing one or more projects (or sub-components) and a test project. The test project contains all of the unit tests.

我们倾向于使每个组件成为一个解决方案,包含一个或多个项目(或子组件)和一个测试项目。测试项目包含所有单元测试。

We then arrange the solutions into a tree based on modules and components, for example:

然后,我们根据模块和组件将解决方案安排到树中,例如:

//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution

The solution will then contain several Visual Studio projects:

该解决方案将包含几个Visual Studio项目:

//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/Something
//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/SomethingElse
//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/TestTheSolution

There might be more depth to the tree, or less, depending on the number of components/sub-components there are. We also tend to have a "General" solution at the sub system and sub component level with general re-useable stuff.

树的深度可能更多,或更少,具体取决于组件/子组件的数量。我们还倾向于在子系统和子组件级别上具有一般可重用的东西的“通用”解决方案。

We then have a sub system-level solution which ties everything together to build the sub system.

然后,我们有一个子系统级解决方案,将所有内容联系在一起以构建子系统。

We do not use or export to an "include" directory. We let Visual Studio build and link within our sandboxes. We have a separate "Release" sandbox to ensure we don't accidentally link the wrong library.

我们不使用或导出到“include”目录。我们让Visual Studio在我们的沙箱中构建和链接。我们有一个单独的“发布”沙箱,以确保我们不会意外链接错误的库。

#2


1  

I have a related, but different question going on over here as well. I state nmake, but really it's any build system: Scons, Bakefile, nmake, Ant, vcproj

我在这里也有一个相关但不同的问题。我声明nmake,但实际上它是任何构建系统:Scons,Bakefile,nmake,Ant,vcproj

The way I generally structure my code is by "module" within an application or DLL. I haven't tended to use namespaces, but that doesn't mean you shouldn't.

我通常构造代码的方式是通过应用程序或DLL中的“模块”。我没有倾向于使用命名空间,但这并不意味着你不应该。

Within the IDE I have something like this:

在IDE中我有这样的东西:

/solution
   /prj1
      /headers
        /module1
        /module2
      /resource
      /source
        /module 1
        /module 2
      /test
   /prj2
      /headers
        /module1
        /module2
      /resource
      /source
        /module 1
        /module 2
      /test

On the file system I have something like this:

在文件系统上我有这样的事情:

/solution
    /prj1
       /bin
       /build
       /include
          /module1
          /module2
       /lib
       /res
       /src
          /module1
          /module2
       /test
    /prj2
       /bin
       /build
       /include
          /module1
          /module2
       /lib
       /res
       /src
          /module1
          /module2
       /test

#1


1  

We tend to make each component a solution, containing one or more projects (or sub-components) and a test project. The test project contains all of the unit tests.

我们倾向于使每个组件成为一个解决方案,包含一个或多个项目(或子组件)和一个测试项目。测试项目包含所有单元测试。

We then arrange the solutions into a tree based on modules and components, for example:

然后,我们根据模块和组件将解决方案安排到树中,例如:

//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution

The solution will then contain several Visual Studio projects:

该解决方案将包含几个Visual Studio项目:

//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/Something
//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/SomethingElse
//depot/MyProject/ASubSystem/AComponentOfTheSubSystem/ASubComponentWithAVSSolution/TestTheSolution

There might be more depth to the tree, or less, depending on the number of components/sub-components there are. We also tend to have a "General" solution at the sub system and sub component level with general re-useable stuff.

树的深度可能更多,或更少,具体取决于组件/子组件的数量。我们还倾向于在子系统和子组件级别上具有一般可重用的东西的“通用”解决方案。

We then have a sub system-level solution which ties everything together to build the sub system.

然后,我们有一个子系统级解决方案,将所有内容联系在一起以构建子系统。

We do not use or export to an "include" directory. We let Visual Studio build and link within our sandboxes. We have a separate "Release" sandbox to ensure we don't accidentally link the wrong library.

我们不使用或导出到“include”目录。我们让Visual Studio在我们的沙箱中构建和链接。我们有一个单独的“发布”沙箱,以确保我们不会意外链接错误的库。

#2


1  

I have a related, but different question going on over here as well. I state nmake, but really it's any build system: Scons, Bakefile, nmake, Ant, vcproj

我在这里也有一个相关但不同的问题。我声明nmake,但实际上它是任何构建系统:Scons,Bakefile,nmake,Ant,vcproj

The way I generally structure my code is by "module" within an application or DLL. I haven't tended to use namespaces, but that doesn't mean you shouldn't.

我通常构造代码的方式是通过应用程序或DLL中的“模块”。我没有倾向于使用命名空间,但这并不意味着你不应该。

Within the IDE I have something like this:

在IDE中我有这样的东西:

/solution
   /prj1
      /headers
        /module1
        /module2
      /resource
      /source
        /module 1
        /module 2
      /test
   /prj2
      /headers
        /module1
        /module2
      /resource
      /source
        /module 1
        /module 2
      /test

On the file system I have something like this:

在文件系统上我有这样的事情:

/solution
    /prj1
       /bin
       /build
       /include
          /module1
          /module2
       /lib
       /res
       /src
          /module1
          /module2
       /test
    /prj2
       /bin
       /build
       /include
          /module1
          /module2
       /lib
       /res
       /src
          /module1
          /module2
       /test