简体   繁体   English

Visual Studio 2010 C ++项目结构

[英]Visual Studio 2010 C++ Project structure

I have build a C++ class that accepts a file path and file pattern from the user and searches for the file pattern in the provided location. 我已经构建了一个C ++类,它接受来自用户的文件路径和文件模式,并在提供的位置搜索文件模式。 Ex: C:\\MyProject *.cpp lists all the .cp files in the given location. 例如:C:\\ MyProject * .cpp列出给定位置中的所有.cp文件。

I am able to build and compile the project successfully. 我能够成功构建和编译项目。 Now I want to have a different Project called Executive which just contains a main() and does the same thing as the C++ class mentioned above. 现在我想要一个名为Executive的不同Project,它只包含一个main(),并且与上面提到的C ++类做同样的事情。

Right now the structure looks like: 现在结构看起来像:

VS2010 Solution
  - Navigator
      -Headers
          f1.h
          f2.h
          f3.h
      -Source
          f1.cpp
          f2.cpp
          f3.cpp

Lets say I want to have another project under the same solution and called Main/Executive whose main purpose is to have a main function that does the same thing as the main in navigator project. 让我们说我希望在同一个解决方案下有另一个项目并称为Main / Executive,其主要目的是使一个main函数与导航器项目中的main相同。

My question is that the Executive project under the same solution has main.cpp and probably will also need the copies of all the *.h files of the navigator project. 我的问题是同一解决方案下的执行项目有main.cpp,可能还需要导航器项目的所有* .h文件的副本。 Do I also need to copy the *.cpp file of navigator to the Executive project for main to work? 我是否还需要将导航器的* .cpp文件复制到主项目的执行项目中? Or should I just have main in Executive project and add hte Navigator project as a reference to the executive project? 或者我应该在Executive项目中使用main并添加hte Navigator项目作为执行项目的参考?

Open solution in Visual Studio, from New Project window select "Add to solution" option from that dropdown and name it Executive. 在Visual Studio中打开解决方案,从“新建项目”窗口中选择该下拉列表中的“添加到解决方案”选项并将其命名为Executive。

Now when you have more projects under the same solution, you can go to properties of Executive project and in C/C++ -> General set Additional Include Directories to ../Navigator/Headers;../Navigator/Source; 现在,当您在同一解决方案下有更多项目时,您可以转到Executive项目的属性,并在C / C ++ - > General set Additional Include Directories to ../Navigator/Headers;../Navigator/Source; .

And then in all source files of Executive project you can include .cpp files from Navigator project, for example: #include "f1.cpp" . 然后在Executive项目的所有源文件中,您可以包含Navigator项目中的.cpp文件,例如: #include "f1.cpp" There is nothing wrong about including .cpp file. 包含.cpp文件没有错。

But , much better would be if you open Properties of Navigator project -> General, change Configuration type to Static library (.lib). 但是 ,如果打开Properties of Navigator项目 - >常规,将配置类型更改为静态库(.lib)会更好。 And then in Executive project you set Additional Include Directories to ../Navigator/Headers; 然后在Executive项目中,您将附加包含目录设置为../Navigator/Headers; and in Linker -> General you set Additional Library Directories to the output folder of Navigator project (if you haven't changed it's output directory it is ../Debug for Debug configuration and ../Release ) and in Linker -> Input you add ;Navigator.lib at the end of Additional Dependencies. 在链接器 - >常规中,您将其他库目录设置为Navigator项目的输出文件夹(如果您尚未更改它的输出目录,则为../Debug for Debug configuration and ../Release ),并在链接器中 - >输入您在附加依赖项的末尾添加;Navigator.lib Then in source files of Executive project you need to include .h files only. 然后在Executive项目的源文件中,您只需要包含.h文件。 For making sure that Navigator project is built before Executive project when building whole solution, you can go to solution's properties -> Project Dependencies and set there that Executive project depends on Navigator project. 为了确保在构建整个解决方案之前在Executive项目之前构建Navigator项目,您可以转到解决方案的属性 - >项目依赖项,并在那里设置Executive项目依赖于Navigator项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM