So I'm learning C++ this semester and right on the first laboratory I got a problem which nor me, nor my prof could solve. Our task was really basic. Create a solution, create a project in which create a function and a header file. In the header file is the declaration of the function. Then create a new project (in same solution), add the old one as a reference. Now comes the part which gave me a headache. Add the path of the folder of the .h file into the "Additional Include Directories" section. Well I do that and nothing. I tried diferent locations, but nothing worked. Any idea how can I solve this problem?
Here are some pictures:
The "code". It is not much
The path
Even if the directory is listed, you still have to reference header with #include "yourHeader.h" wherever you want to use the forward-declared functions.
I suggest that you could first manually find the directory where the .h file is located, and then add the path in VS.
If it doesn't work, I suggest that you could add the path in Properties->VC++ Directories->Include Directories.
Also, you could refer to Microsoft Docs for more information.
I reinstalled VisualStudio and now it works prefctly. FML
I started working as a research fellow at my university and was instructed to develop a component for an already existing application written in C++ using an in-house framework, also developed in C++.
Currently I am struggling with properly setting up the project in Visual Studio 2017.
Whenever I try to include a file from the framework, IntelliSense complains about not being able to open the file.
However, following things add to the oddness of the problem:
The solutions properties are set correctly; the project DOES build without any complaints.
Writing the '#include'-directive, IntelliSense DOES suggest the correct relative path to the header files (i.e. #include <framework/class.h>).
I can open the header file from within the source file referencing it, using the 'Open Document "class.h"' dialog.
I have already came across this:
IntelliSense: Cannot open source file in include path
Intellisense cannot open source file "*.h"
So far, nothing solved my issue. Did someone come across this issue yet?
TL;DR
Everything compiles fine.
"C/C++ -> General -> Additional Include Directories" is set properly.
"VC++ Directories -> Include Directories" is set as well.
IntelliSense properly suggests header file, when writing include directive.
BUT IntelliSense reportedly fails to open the file, thus not indexing it.
I am stuck with a fancy but resource hungry text editor.
EDIT:
I am working on a MacBook "13 2016; installed Windows 10 Pro 64-bit via Bootcamp.
This issue occurs because Windows now has the option for making folders case-sensitive and intellisense has a habit of changing the case of files that it tries to open.
Intellisense tries to use a path like C:\WORKSPACEPATH\PROJECTDIR\MYFILE.cpp (i.e. all uppercase), but if C:\workspace (or any of the other directories in the path) are set to be case-sensitive and don't exactly match, it won't be found.
In my case it was because I created the folder via WSL which enables case sensitivity by default on any new directories it creates (including via things like git clone). See here
Easy Fix
This can be fixed by running the following:
fsutil file setCaseSensitiveInfo <directory> disable
More Commands
You can check whether a folder has case sensitivity enabled by running
fsutil file queryCaseSensitiveInfo <directory>
and Finally, a handy one-liner to disable this recursively:
for /r /d %f in (.) do (fsutil file setCaseSensitiveInfo %f disable)
(This info was originally posted as a comment to the original question, before it turned out it was in fact the same problem. See the comments for input from a couple of other people)
For a Linux project open in Visual Studio 2022, I tried the accepted answer from #yothsoggoth, , which makes sense to me, but unfortunately didn't work.
I realized that visual studio couldn't even open the C++ file from the standard library using F12 but it could open others from other libraries.
So in my case the solution was to close visual studio, backup the folder working as a cache.
C:\Users\[user]\AppData\Local\Microsoft\Linux to C:\Users\[user]\AppData\Local\Microsoft\Linux.bak
Then I reopened Visual Studio and let CMake to regenerate the cache.
The errors now are gone and I can now even open <string> and others from the C++ std library with F12.
I hope this workaround helps others
So I've looked into this issue, and nothing has helped me so far. I've read numerous topics, many people say the same things about it not actually being able to find the file. In my project, I can right click the header where it is including (and giving the fatal error) and it will open the header file, everything loads works perfectly fine in the editor, but Visual Studio still tells me that the file cannot be found while compiling. I've double checked the spelling, I've added the double quotation marks around the includes and additional libraries, and removed them, and nothing is working.
I'm trying to include the header files for MySQL. I added and tried the include and library directories as well as libmysql.lib to the proper locations (Additional include directories, additional library directories, and Additional dependencies) with (to my knowledge) most combinations of directory paths.
The folder structure has the mysqlcon folder in the solution directory, and the project in its own folder. When I include the mysqlcon\include and lib folders. I tried:
..\mysqlcon\include
"..\mysqlcon\include"
$(SolutionDir)\mysqlcon\include
$(SolutionDir)\\mysqlcon\\include
Nothing seems to be working. I'm at a total loss. I even rebuilt the entire project today, got all the dependencies, references, build order, files, vcprojs redone, and I'm back staring at the same problem.
Found a solution... I'm not sure why it worked before, but I changed
#include "mysql.h"
to
#include "..\mysqlcon\include\mysql.h"
and it worked perfectly.
As the title says, I've removed a file from a project I'm working on but it still shows up in the build (well, the errors that is).
I have no idea why it would do that. I cleaned the project and did a full rebuild. I checked everything in the Solution Explorer but can't find the file.
Removing the files from the project directory is not enough you need to remove the actual file from the file system to avoid ambiguity so navigate using the windows explorer and delete the file.
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':