0

In my file explorer, my C++ project folders are like this:

... -> Documents -> C++ -> Files . . . . Projects

[In C++ folder, there are two more folders, called Files and one called Projects. I keep all my games/projects in the Projects folder. Each game has its own folder inside.]

Now here's the problem: I want all my common functions (.cpp & .h) to stay in one file folder, so if I ever change it, it changes for all my games. I want to keep these in Files. Is there a way to achieve this, like #include [Directory]? I know I can keep a file in its own game, but I want these to be all changed easily, and my code does not need to be transferred between computers. Thanks

5
  • Most IDEs allow to add custom include paths and files to be compiled. Commented Jan 29, 2018 at 16:46
  • @PaulGötzinger I am using Microsoft Visual Studio, 2017. I am not sure how to do that. Commented Jan 29, 2018 at 16:47
  • 2
    learn.microsoft.com/en-us/cpp/windows/… Commented Jan 29, 2018 at 16:52
  • @bolov I have seen you on my previous post. Thanks, I will look at that :) Commented Jan 29, 2018 at 16:53
  • There is no requirement that the folder structure in the IDE must match the folders on disk. You can pick a file from anywhere and add it to the Files folder. Commented Jan 29, 2018 at 17:06

2 Answers 2

3

This is not the right way to do it. If you have functionality that is shared between different applications (games, in your case), make a library from them and include that library in all your projects.

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

1 Comment

I am not sure how to make a library, I'm going to have to try and find that on the internet
2

Solution for Visual Studio (2017)

For Source Files: In the solution explorer right click on Sourcefiles and click "Add"/"Add existing" and choose your file(s)

Setting Include directory:

  1. In the solution Explorer right click on your "Project" and click Properties
  2. On the top set "Configuration" to "All Configurations"
  3. Choose in the lsit on the left "VC++ Directories"
  4. Click on the Dropdown arrow on the row with "Include directories" (you might have to click once on the row for the arrow to appear
  5. Click "edit"
  6. Add one line for each include directory. Use the folder icon on the top to open the file explorer to choose the directories

4 Comments

This is the way I would do it. You could create a single .h file in your Projects/ directory that includes all of your project headers, and only #include "Project-MainFile.h" in your actual projects.
I have done this, and it wrote in include directories: C:\Users\George\Documents\C++\Files\.cpp & .h;$(IncludePath) , but I can't find out how you include it.
"but I can't find out how you include it" what do you mean exactly? You still need to write #include <name.h>in your source files.
Do you have seperate folder for source files and headers? Because in the include directories you only need to add the header folder without file extension. e.g.: `C:\Users\George\Documents\C++\Files`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.