0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I edited my answer, wrote there another (better) way how to do that.
This answers my question ThanksLihO I will try it out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.