Deepak B
Deepak B

Reputation: 2335

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. Ex: C:\MyProject *.cpp lists all the .cp files in the given location.

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.

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.

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. Do I also need to copy the *.cpp file of navigator to the Executive project for main to work? Or should I just have main in Executive project and add hte Navigator project as a reference to the executive project?

Upvotes: 0

Views: 910

Answers (1)

LihO
LihO

Reputation: 42133

Open solution in Visual Studio, from New Project window select "Add to solution" option from that dropdown and name it 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;.

And then in all source files of Executive project you can include .cpp files from Navigator project, for example: #include "f1.cpp". There is nothing wrong about including .cpp file.

But, much better would be if you open Properties of Navigator project -> General, change Configuration type to Static library (.lib). And then in Executive project you set Additional Include Directories to ../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. Then in source files of Executive project you need to include .h files only. 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.

Upvotes: 2

Related Questions