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.
Related
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.
I have started learning C++ with Visual Studio 2019 and noticed a strange behaviour. When you create an empty project you are represented with "Filter" files. Now if I active "Show All Files" I can create directories. I created the following structure:
/Core/
/Engine/
Main.cpp
Now if I create a "class" it is, by default, created next to Main.cpp. I would then move the Class.h and Class.cpp into /Core/.
Now if I start editing the newly created files I loose Intellisense. If I uncheck "Show All Files" I get it back. Does anyone else have the same problem?
Another question I wanted to ask was about filter files and project folder structure. Should I use the filter files to organize my project or an actual folder structure? I'm slightly confused because of the Intellisense problem, that's why I'm asking.
And if I should create a folder structure, how should I handle includes like this #include "..\..\... \FileUpInTree.h". In Javascript and Webpack you could define "Alias" Directories to eliminate this. I was wondering if something like this exists for Visual Studio aswell. Maybe namespaces?
Now if I start editing the newly created files I loose Intellisense.
If I uncheck "Show All Files" I get it back. Does anyone else have the
same problem?
I have faced the same issue as you described and when I migrate a file to another folder under the Show All Files filter, Intellisense does not work, which is really strange. When I didn't migrate the file, Intellisense works well at the default address.
And I have reported this issue on our DC Forum and you can add any detailed info on that link and also anyone who is interested in this issue will vote it so that it will make Microsoft attach great importance.
The workaround is that you should uncheck Show All Files and then click it again. After that, Intellisense will turn back and works well.
Another question I wanted to ask was about filter files and project
folder structure. Should I use the filter files to organize my project
or an actual folder structure? I'm slightly confused because of the
Intellisense problem, that's why I'm asking.
Actually, when you use the default project type in c++ projects(not click Show All Files), this structure will automatically identify each file in your project and categorize it into its own filtering folder. At this time, the intellisense works perfectly, because subdividing various files will not conflict.
But in this format, you cannot create folder structure.
Besides, using the filter files or the actual folder structure are the same effect. If you use actual project structure in the Windows Explorer, it will be showed under solution explorer(click Show All Files) automatically.
Suggestion
As long as you do not want to migrate files at will, you can use Intellisense under this filter.
Or
1) create folder structure under Show All Files and then uncheck Show All Files to get Intellisense.
And if I should create a folder structure, how should I handle
includes like this #include "....... \FileUpInTree.h". In Javascript
and Webpack you could define "Alias" Directories to eliminate this. I
was wondering if something like this exists for Visual Studio aswell.
Maybe namespaces?
I think you do not need to worry about this too much.
When you want to use the file under the folder structure of the project, you can just use #include"xxx.h" and the Intellisense will automatically grab the header file in the project.
And if you want to reference a c++ class, you can just use namespace <the c++ class namespace>.
The story
I'm trying to load a C++ project with Visual Studio, and as I used CMake, I used it to generate a .sln file.
My sources files are regrouped in separate folders, but the solution explorer listed them all in a "Source files" folder. Thanks to this question, I solved this first problem.
But then I realized that only .cpp files were listed, so I added new virtual directories one by one to make the folder architecture as it was on my folder list in include side.
But then again I tried to create a new file in a virtual folder, and realized that it didn't move at all at the right place in real.
The question
So now, I just want to forget this "virtual directories" system, and make the solution explorer to be nothing more than a folder tree as it is in real, just like a windows explorer.
Is there any way to do that after an initialization of .sln file with CMake?
UPDATE:
I'm not wishing to use a CMake command because It does not resolve creation problems, nor anything that would pass through the actual solution explorer because each time that I edit a CMakeFiles.txt file, the solution reload reset the solution explorer and I loose every manual include previously done.
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.
This might be a silly question but I am still learning. I have read several books on creating application and creating a good directory structure. When people talk about creating a directory structure, do they mean the folders you make within the solution explorer (folders you actually find inside of a .sln file) or do they mean setting up and creating folders that reside in the same folder as your .sln file or your compiled application (.exe). I figured the solution explorer folders are different from a typical windows folder cause the folders I create inside my .sln file are no where to be found on my windows system.
Visual Studio has a strange way of dealing with "folders" in solutions. A "Solution Folder" is not actually a physical folder, but more of a virtual folder managed by Visual Studio. Your files may end up in the root directoy, but VS will treat them as if they are in a "folder." This is configured and managed in the VS .sln or project file.
I'm not a fan of how this works in Visual Studio, I don't get why they don't just put files in physical folders. It's up to you whether you want to fight VS and try to keep your files in physical folders, or if you want to just let VS manage it, but ultimately, it really doesn't matter.
a typical directory struction will be like
bin (binaries)
Src
->.sln
->common
->.prj
->Project1
->.prj
->Project2
->.prj
Lib (3rd party lib's)
Doc (documentation)
Tools (3rd party tools)
Setup (setup projects)
Test (test cases)
With C++ in Visual Studio your solution directories need not match the filesystem, but they can.
Typically people refer to the directory structure as the filesystem layout of the project.
It's typical to have visual studio directories called headers and source, you wouldn't lay your project out like this on your filesystem though.
Visual Studio directories aren't just virtual folders though, they can contain filter rules so when you add a file to your project it will automatically get added to the correct filtered folder. They can also specify whether the folder should be under version control or not. And whether they should be parsed for auto complete or not.
Typically on filesystem I will create 1 folder per project and rarely create subfolders inside an individual project. But in the solution explorer I will create top level folders which I put projects into (For example: "Server Components" and "Client Components"), as well as in project folders to group things logically together (For example: Config, GUI, Controllers, ...) so I can find what i'm looking for faster.