Visual Studio 2019, no Intellisense with "Show all files" - c++

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>.

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.

Visual C++, Organize .h and .cpp Files in Folders

I've never had a C++ project that has required organizing stuff in folders before, because I mostly use C# for everything, but now I have this kind of project. What I have done is right click on "Header Files" in the solution explorer, and looked for "Add Folder", but there is no such thing. However, there is something called a "Filter", and it appears to work like a folder, but I don't know if this is how C++ uses folders, or what. Is this the case, using filters as folders, or is there a way to make folders?
Thanks for your help.
You can use filters if you like. These place files into pseudo-folders based on their file extensions. By default, you get header files in "Header Files", source files in "Source Files", etc., but these are customizable, as you've found out.
However, if you prefer the Solution Explorer to reflect the file system, then that is an option as well. Just click the "Show All Files" button at the top of the Solution Explorer to toggle it on. The filters will no longer be active (although they'll still be saved with your project settings so that you can toggle them back on at any time), and you will see the folders exactly as they are in the file system. You can drag-and-drop files between folders, create new folders, and everything, just as you normally would.
(overcompressed JPG image stolen from Ben Williams' blog)
I prefer to keep the filters disabled and see the file system in the Solution Explorer. But I'm a control freakā€”I like files to be exactly where I put them.
The obvious drawback of this, of course, is that you'll see all files in your solution's directory on disk, even those that have not been added to your project/solution. Those that have not been included will appear grayed out or with a dotted outline, and can be easily included by right-clicking and selecting "Include In Project."
You can add projects to Visual Studio solution. Each project would be in separate folder. They also can be stored hierarchically.

Using sub folders in the Source folder for Visual Studios 2010

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.

Visual Studio can't 'see' my included header files

I created an empty 'Demo' project in Visual Studio 2008 and added some existing projects to my solution. Included "MyHeader.h" (other project's header) in main.cpp file which is in 'Demo'. Also added header files' path in "Tools/Option/VC++ Directories/Include files" section. But intellisense says: "File MyHeader.h not found in current source file's directory or in build system paths..."
How the problem can be fixed?
Delete the .sdf file that is in your solution directory. It's just the Intellisense database, and Visual Studio will recreate it the next time you open that solution. This db can get corrupted and cause the IDE to not be able to find things, and since the compiler generates this information for itself on the fly, it wouldn't be affected.
If you choose Project and then All Files in the menu, all files should be displayed in the Solution Explorer that are physically in your project map, but not (yet) included in your project. If you right click on the file you want to add in the Solution Explorer, you can include it.
This happened to me just now, after shutting down and restarting the computer. Eventually I realised that the architecture had somehow been changed to ARM from x64.
In Visual Studio 2019 in my case I copied a header file into the project directory, just near the other files. Intellisense could see it, but the build failed. Fair enough, it wasn't actually added to the project. I added it as existing item but this is the point that Visual Studio still didn't account for it.
Solution:
Close the project.
Delete the .vs directory.
Reopen the project.
Now Visual Studio recreates the directory with everything in it and it can now see the included file.
If it is the case that only the IDE indicates that it cannot find included files, but compiling is successful, the issue is simply that IntelliSense is not fully up to date with recent changes. This can happen specifically when including existing projects, in my own experience.
Deleting the .sdf file (= IntelliSense database) that is generated in your solution directory forces Visual Studio to regenerate it, so that it is up to date again. Just doing a "clean" will probably do the same thing, but takes more time since everything will be generated again then.
I know this is an older question, but none of the above answers worked for me. In my case, the issue turned out to be that I had absolute include paths but without drive letters. Compilation was fine, but Visual Studio couldn't find an include file when I right-clicked and tried to open it. Adding the drive letters to my include paths corrected the problem.
I would never recommend hard-coding drive letters in any aspect of your project files; either use relative paths, macros, environment variables, or some mix of the tree for any permanent situation. However, in this case, I'm working in some temporary projects where absolute paths were necessary in the short term. Not being able to right-click to open the files was extremely frustrating, and hopefully this will help others.
Had the same problem. Double check if you added the include files to Debug or Release Version of your project. If you only added it for one of them and compile for the other VS will just play dumb and not find them.
Try adding the header file to your project's files. (right click on project -> add existing file).
In my experience, with VS2010, when include files can't be found at compile time, doing a clean, then build usually fixes the problem. It's not that rare for the editor to be able to open an include file and then the compiler to announce that it can't find that very file, even when it is open on the screen!
If the visual studio says that you miss some file in the current source file folder, there is one solution that i used. Just right click the file you want to add and choose Open Document, if it really doesn't exist, then you should see something like cannot find file in the source file path = "somewhere in your computer", then what you could do is the add your source file into that path first and see if it works.
I had this issue after upgrading to Visual Studio 2019 from 2015. It would compile the project fine but Intellisense and the IDE couldn't find any header files.
The project only had valid configuration for Win32/Debug. Include paths were not setup correctly for other environments. Even though Visual Studio displayed the current environment as Win32/Debug, Intellisense must have been using something else.
Changing the current environment to x64/Release, and then back to Win32/Debug fixed it.
In Visual Studio, click on Project > Rescan Solution as shown below to rebuild the project database.
Here's how I solved this problem.
Go to Project --> Show All Files.
Right click all the files in Solutions Explorer and Click on Include in Project in all the files you want to include.
Done :)
I encountered this issue, but the solutions provided didn't directly help me, so I'm sharing how I got myself into a similar situation and temporarily resolved it.
I created a new project within an existing solution and copy & pasted the Header and CPP file from another project within that solution that I needed to include in my new project through the IDE. Intellisense displayed an error suggesting it could not resolve the reference to the header file and compiling the code failed with the same error too.
After reading the posts here, I checked the project folder with Windows File Explorer and only the main.cpp file was found. For some reason, my copy and paste of the header file and CPP file were just a reference? (I assume) and did not physically copy the file into the new project file.
I deleted the files from the Project view within Visual Studio and I used File Explorer to copy the files that I needed to the project folder/directory. I then referenced the other solutions posted here to "include files in project" by showing all files and this resolved the problem.
It boiled down to the files not being physically in the Project folder/directory even though they were shown correctly within the IDE.
Please Note I understand duplicating code is not best practice and my situation is purely a learning/hobby project. It's probably in my best interest and anyone else who ended up in a similar situation to use the IDE/project/Solution setup correctly when reusing code from other projects - I'm still learning and I'll figure this out one day!
If some soul has scrolled down to this bottom, what worked for me was disabling the Disable Database option i.e. set it to False under Tools|Options|Text Editor|C/C++|Advanced. For some reason, it was set to True for me.
As per docs, if it's set to True
All use of the code browsing database (SDF), all other
Browsing/Navigation options, and all IntelliSense features except for
#include Auto Complete are disabled.
None of the solutions worked for me. Here is what was the issue for me:
(Note discrepancy in build configuration and VC++ Directories (x86 vs x64)
To fix, just changed the build configuration to 'x86':

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.