Using sub folders in the Source folder for Visual Studios 2010 - c++

I am currently creating a small project over the summer using c++ and visual studio 2010. I wanted to organize the individual .cpp and .h files into their own folders in the project directory. While I use filters in the actual project, I do understand that these are filters, not folders.
So my question is this. In my source, I currently have a header folder called GameStateManger.h, and a folder called Tank_Headers and Tank_CPPs. I also have Tank.h, and Tank.cpp, in their respective folders. My problem is that in GameStateManager, I have this #include "Tank_Headers\Tank.h", however, in my Tank.h, when I type #include... nothing shows up. I cannot find anything. However, if I make a new header, and put it in just source, I can search for those folders. I want to be able to organize my .h files and my .cpp files into individual folders in my source folder, so it is much more organized, considering the project might get very big very soon.
Thank you!

try to use #include "Tank.h"
That should work as long as you add the file to your project first. Drag it from explorer into whatever filter you want it organized it into.
Sorry I forgot to add:
You need to add the subfolder to your project. Go to the project properties, look under C/C++ and add it to Additional Include Folders.

Related

Visual Studio 2019: Linking to folder

I am trying to link to a folder that is not inside the project directory. To give an example,
If my project is in C:\project and I have a folder C:\shared, how can I manage to link C:\shared into the project (and being able to edit/view the files in Solution Explorer) without making a copy of the directory and placing it into the project directory.
I need this due to the fact that many projects will use this folder and it would be ideal to have them edit/use the same files rather than copy the folder into each project individually. That way if a bug is fixed in one project, all other projects will now use the fixed files as well.
For more context, this is a C++ project using Visual Studio 2019.
What I've tried/considered.
Additional include directories
Problem: This does not show the files in the Solution Explorer
Dragging/dropping the folder (or copy/pasting) as seen in another StackOverflow thread.
Problem: This just crashes my visual studio completely. The folder is quite large so I assume that's related to why.
Appreciate any insight on how to proceed. It's really unfortunate that this is a pain, I would think that something like this would be common, but all the posts I've seen related to it have either gone unanswered or could not be applied to my situation.
Thanks.
Shared Projects are the key here.. I just found out they existed. After creating one, drop the folder/files in the same directory that has .vcxitems file. Now in the project you want to include the shared folder, right click your solution, Add -> Existing Project and select your .vcxitems file.

How to use subfolders of the VC++ Include Directories in Visual Studio 2017

I have a given solution, not written by me, from Visual Studio 2015 in C++ with a rather complex structure and many source files.
The solution uses some header files from an outside application, that are organized in one folder containing 268 subfolders, containing other folders and/or header files.
An illustration of the header files folder structure:
In other words the outside application has a tree structure of header files to be used when developing custom code for it.
I am using Visual Studio 2017 and I know that in order to use a header file like #include <hfile.h> I need to specify its location in Configuration Properties -> VC++ Directories -> Include Directories. The problem is that subfolders of this entry are not scanned and I have 268 subfolders and a big project where I cannot edit all includes.
I think there should be a better way to reference all header files used in the project.
Can someone help me in this situation?
Thanks!
Visual Studio cannot be configured to look recursively into subdirectories of directories on the include path (ref).
That way absolute madness would lie as the potential for conflicts would skyrocket, and the time to resolve includes would also go up.
I'm sorry that you have so many subfolders, but the solution is to fix that. That's an insane project layout. Getting rid of all those "copies" would be a good start…

How do I get Code::Blocks to display .h and .cpp files in the same directory?

I am very slowly figuring out Code::Blocks and am trying to set it to my liking.
The gentleman that provided the second answer in this post: Organization of files in Code Blocks seems to be able to get C::B to display his header and source files in a single directory in the project tree. This is what his project tree looks like (and how I want mine to look):
However, in my case, anytime I create a header file, C::B displays it in a new directory called 'Headers' (see image below). I should mention that I am keeping the .cpp and .h files together in the same directory when I am creating the files.
I looked all over environment settings, project properties, C::B documentation, online, tried to ask the poster of the link (but i don't have enough reputation to put comments) and I am stuck. Very stuck.
If you know where the setting in C::B which needs to be changed to display the two file types together (like in the link above), I would really appreciate your help.
The Sources and Headers folders that by default appear to contain
respectively the source and header files of a C::B project are virtual
folders that represent the "categories" (header, source) of the files
within.
To disable this virtual organisation of your project:-
Right-click on your project icon in the project workspace
From the pop-menu select Project tree
In the Project tree sub-menu uncheck the item Categorize by file types

How to add class to openframeworks project in VS2012

I am normally a C# guy but trying to get into c++.
I made myself a new openframeworks project by copying and pasting one of the example projects and then renaming everything to my project name. (If there is an easier way, I would love to hear it)
This project has the .cpp and .h files in a sub folder called "src" which are in turn organized into virtual folders (filters???) in visual studio.
How can I add a class to this project from within visual studio?
If I right click on the src filter in the solution explorer and hit add class. It creates the class files at the root of the project not in the src folder. I mean it does this both in the solution explorer and where it physically places the files. This is a problem because I can't include my class files in the rest of my app, presumably because they aren't in the same folder
What is the proper way to add a class file?
When you right click on the filter (could be the "src" or a new one) and hit 'Add class', after hitting 'Add' in the first screen, in the next one you will find a [...] button besides each text input field for the .h .cpp files: with that button you can chose the folder where your files are going to be saved ('src' or any other).
It isn't a good solution but the only way I have found to do this is to add the class in visual studio, which places it in the root. Exclude the files from the project. Move the files to the src folder using Windows Explorer. Include them in the project by showing all files and then right clicking to include in project. At this point I would expect the files to be listed in the project but don't appear until I reload the project. Once the project is reloaded I then drag and drop the files into the src folder/filter

Create file/folder structure in VS 2010

I am somewhat of a novice and am seeking some help.
I am working in Visual Studios 2010 and have my solution that has my project that I am currently working on. Specifically I am working on a Win32 Project. I don't know if that is important to know or not.
I have made a file/folder structure in the directory I am working on to help organize my sources. I would like to mimic that in the project but can't. After organizing my sources it says that some can't be found when I compile. I have alleviated some of the problem by editing some of the #include statements but there are still some I can't fix as they need to include a file from one folder higher (I guess the parent folder?) and I don't know how to do that in an include statement.
Is there anyway I can have actual physical folders in my project that mimic my structure? If so will it handle the #includes fine? (IE if I say #include "BaseClass.h" and its in the folder one higher (again I guess parent folder?) will it find it?).
I've tried dragging my files/folders over from the solution explorer but it just adds them. I have also tried to use the Add New Filter (it has a folder icon) and it does indeed create a "folder" in the project but they aren't physical folders. They are just there to help organize the files in the Solution Explorer for the project.
I've tried Google searching:
create folder visual studio 2010 project
add folder visual studio 2010 project
create file structure visual studio 2010 project
And they just direct me to drag over the folders from my Solution Explorer and again they don't actually add the folders. They do speak of a template but I don't know if thats what I need to do. I am not technically skilled enough yet to understand it all so would need to do more research. Any pointers/help would be much appreciated.
The way to add physical folders to a project is this:
Create the physical folder in Windows Explorer.
Select the project in Solution Explorer and click Show All Files.
Right click the folder and select Include in Project.
Now you have the folder defined in the project and you can right-click on it and do Add New Item and the new item will get created in the physical folder.
Caution - if you create a Class, the namespace will include the folder name.
It's a little different at the solution level since Show All Files doesn't work and there is no Include in Solution.
What I've done is create the physical folder, then do Add New Solution Folder and give it the same name. Seems to work.
You can fix failure to include by appending ";.." (this means "one level up from here") to the list of include paths to check. Right click 'Project', select 'Properties', locate 'C/C++', 'General', 'Additional Include Directories'. Make sure you do this for both Debug and Release configurations.
I've always found relating Visual Studio folder structure in Solution Explorer to the physical files painful, so I generally avoid this.
So you have some structure on the file system
A
A.sln
A.prj
A.h
Base
B.cpp
B.h
Derived
C.cpp
C.h
D.cpp
D.h
SomeOther
E.h
C and D can refer to B in various ways
#include "../B.h"
or
changing the project settings to add to the include folder list "Base" then
#include "B.h"
C and D could also refer to A
#include "../../A.h"
or SomeOther
#include "../../SomeOther/E.h"
'..' in a path indicates to go up one parent
prefer unix style '/' to windows style '\' for portability, but either will work.
Be cautious with structure, MSVC doesn't help you manage it like eclipse helps manage packages in Java, it can become more of a hassle than a help if you make too many small folders.
In the solution explorer, right click and choose Add Project Folder (or something similar, I don't have VS available to view right now). You shouldn't move the files in Explorer after they have been created in VS, as it will affect all the references.
Whenever possible, perform all file moves/renames/changes within the VS IDE.