Visual Studio Cannot open include file; No such file or directory - c++

Linking files is going to be the death of me.
So, I have had this problem many times before in both Visual Studio for C++ and Eclipse for Java. Right now I'm having problems in visual studio while trying to setup a project so I can start messing around with the Kinect SDK. The first thing I did was to include the NuiApi.h
#include <NuiApi.h>
I made sure to go into the VC++ directories and add the correct include directories $(KINECTSDK10_DIR)\inc and $(KINECTSDK10_DIR)\lib\x86 for the library directories. I also went to the Linker and added the Kinect10.lib in the additional dependencies in the Input section.
I still had the problem even after including these directories into the project. So I did some exploring and went to C/C++->General and added the include directories in the "Additional Include Directories" portion again just to see if that would fix it... that did nothing.
So I went back to the linker and added the library directories under General in Additional Library Directories to see if that would do anything and it still has not.
I'm at a complete loss right now and am so confused as to why these files aren't being included correctly! I swear this happens every time I try to work with a new API and I have to fiddle with it until it starts working for some reason. Am I doing something wrong? Am I missing something stupid? Does anyone have any ideas?

The difference between quoted and the angle-bracket form is explained here for visual studio. In principle, the quoted form is used for project specific includes, whereas the angle form is used for system libraries. In your case, the angle-bracket seems to be the right form.
What you have to do is to add the include to the C++ directories :
Right click on project -> Properties
VC++ directories
You should keep in mind that this setting is configuration-dependent, i.e. you have to do it for debug mode, but you'll have to repeat it for release mode.
Finally, you should make sure that the environment variable KINECTSDK10_DIR points to the right location (Windows+X -> System -> Advanced system parameters -> Environment variables). Attention: if you edit these parameters, you'll have to restart visual studio so that the new environment is taken into account.

Related

How can I tell Visual studio where my additional .dll files are?

I have recently switched my IDE to Visual Studio 2019 for C++ projects. I easily followed a tutorial into setting up a new library like SFML into visual studio, and tell it where the additional include and library directories are.
But there is something else that is required for it to work, which are the .dll files. Every page I followed, even the Documentation by the SFML website, it says that they have to be in the same directory as my project. That means I need to copy-paste the 7-8 files into my project directory. This really makes the folder look untidy. I would like to create a new folder and tell Visual Studio where those files are. I tried going doing this
Project -> Properties -> Linker -> Input -> Additional dependencies
Usually, the lines that would work are
sfml-system-d.lib
sfml-window-d.lib
...
I tried doing $(ProjectDir)valid path\ sfml-files.lib but this gives me the linker error, saying that It could not find the file.
If I simply move the .dlls into a folder without doing anything, the code would compile and link fine. But when it runs, Windows gives me a pop-up box with the same error message.
Here is how it currently looks
Looks really messy, I just want to be able to move them into dependencies like how src contains the source files.
How can I achieve this?
As it is now, it works perfectly fine. The issue only occurs when I try to create a new folder.
I hope I have covered the important information required for a good answer, If not please let me know what more I should add
Microsoft Visual Studio 2019
Currently running 64-bit platform with Debug configuration. Hence the -d suffix
You could create a path environment for your specified directory, which is like drescherjm’s suggestion. The steps:
Right-click “This PC” -> “Properties”-> “Advance System settings”
Click “Environment Variables”
In the System Variables group, edit “Path”
Add your directory, for example: ”D:\ SFML-2.5.1\bin”
Restart your visual studio and re-open your project
The easier solution might be to put them in the x64 subdirectory. This allows you to have various builds side by side (x86/x64, debug/release).
Since this x64 directory is where the EXE is located, it is the first directory searched for DLL's. It will take precedence over the Path solution suggested in the other answer. The Path directories are searched last of all.

visual studio not seeing my include files

This may be a very simple question but I haven't been able to figure it out so any help is appreciated.
I have a header that is located in a general folder because I want to use it in several projects for example:
C:\user\geninclude\program\header.h
I created a new empty project with a very simple main, in the main I put
#include <program/header.h>
I then went to the project properties and in VC++ in include directories added C:\user\geninclude\
but when I tried to build the program the program tells me it cannot find header.h because is not in the current directory or in the build system path.
I also tried in the project properties in C/C++ general Additional Include Directories adding C:\user\geninclude\ but still the same error.
I know is something simple I am missing, but I don't know what, I am very new to this just learning.
For reference I am using Visual Studio 2013.
Thank you in advance for your help.
UPDATE: Thank you all for your kind responses, I have tried everything you have told me (check release vs debug in both instances, change / for \ and <> for "", and double checking the header and still the system does not see it. It really is very weird. I'll keep trying...
Please check if your file is really an header file otherwise it won't appear on include.
What you can also do (as a workaround if you need that method fast) is to put your header file (or folder with header files) on the visual studio "include" folder. The path should look like this "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
PS: You should also check the properties configuration when you're adding the path to VC++ include directories. You could be adding the path to debug configuration and trying to run it in release mode.
You do indeed want
Project Properties -> Configuration Properties -> C/C++ -> Additional Include Directories
(or something close to that; I'm using VS 2008). Make sure the configuration you're editing in the top left (debug/release) matches the configuration you're building with (typically visible up top in the main window). So it sounds like you may have done it correctly; I'd double-check for the file's existence in that location. You could also try program\header.h instead of program/header.h. If none of those work, try adding C:\user\geninclude\program to the include directories (no \ at the end) and change it to #include "header.h". If that doesn't work either, you've almost surely got the header file in the wrong spot.
Another thing that can cause include files not being picked up is a difference between the platform set in your c++ project's Property Pages and your "Active Solution Platform" in configuration manager. Can just check if one is set to x64 and the other x86
check if you have specified the path correctly. for example I had written cpp instead of c++ and therefore suffered a lot and wasted like an hour searching here and there.
For Visual Studio 2019 users:
Project(P) > yours_project_name properties(P) > Platform Toolset Visual Studio 2019(V###)
Reasoning: You might download the project from Online and they used other version of Visual Studio as Platform.
Project(P) > yours_project_name properties(P) > Windows SDK Version ##.#(latest installed version).
Reasoning: You might download the project from Online and they used version SDK 8.0 while you have SDK 10.0
ntucvhw

Visual studio c++ problems including poco

I am new to c++ and visual studio and am struggling with getting an include statement to work. I want to test out poco for online applications with c++ and found a basic example online that used
#include <Poco/String.h>
However, my Win32 project in visual studio throws an error stating "could not open include file". I added the path to project properties < VC++ Directories < Include Directories. I also added the path to linker < input < additional dependencies. I can't seem to get rid of that red underline and error though. When I am typing my include statement a list pops up but the directory listed is the "...Windows Kits\8.1\um\". Could anybody lend me a hand? I really appreciate any help. Thank you. Let me know if I can provide more info.
It should be added to 'C/C++ > Additional Include directories'
and it should be added as:
c:/some_folders_down
not
c:/some_folders_down/Poco
You say, 'Adding the directory'. You don't want to add the Poco folder to your path because when you #include <Poco/String.h> you are adding that part of the path there. Try:
#include <String.h>, if that works, fix your additional include path. Would you paste that path?
So apparently the default for visual studio is to add the the "additional directories" paths to Debug x64 since I am on a 64 bit OS. However, I forgot to switch to x64 in the solution platform drop down at the top of the VS window. If you right click on the .vcxproj and search for "AdditionalIncludeDirectories" you can view this directly. I feel like a facepalm is in order haha. Thanks so much to everyone who viewed my question.

Visual Studio 2012 - error LNK1104: cannot open file 'glew32.lib'

I am having issues compiling a basic openGL program on VS 2012. I get a build error upon compiltation giving me:
1>LINK : fatal error LNK1104: cannot open file 'glew32.lib'
I followed the instructions given to me by the documentation for GLEW.
In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.
Also you must include #include in your sources; For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;
C/C++ Tab -> General -> Additional Include Directories - Add lib folder there
I have also added the glew32.dll onto my Debug folder within my project folder along with the executable. So far I keep getting this error.
If you need any more further clarification of the steps I have done please don't hesitate to ask
In all honesty, there is no real benefit to using the DLL version of glew (short of reduced executable size, but this hardly matters on modern Windows PCs).
It is not like you can simply drop a new version of the DLL into your application and use extensions that you never used before. Likewise, bug fixes are so infrequent/unnecessary with a library that basically just parses the extension spec. files that using the DLL as a means of fixing extension loading bugs in shipped software is also not practical. Statically linking to glew (this means glew32s.lib) makes much more sense in the long run.
The static linking library is also more portable on Windows, it will work with MSVC and MinGW (whereas the DLL library only works with MSVC). Link against glew32s and put that in whatever directory you decided to use for additional library dependencies.
Here is a sample solution configuration for a project I wrote that uses glew. I have established a convention for this particular software where compile-time dependencies are stored under platform/<Subsystem>. Thus, I have glew32s.lib (32-bit) and glew64s.lib (64-bit) in ./Epsilon/platform/OpenGL/glew{32|64}s.lib
Steps to Use Classes form another project (Add header and solver linker errors)
To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
"Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
"Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.
This sounds like the library has been specified as a dependency, but the linker/additional search path(s) has not been set to include the directory where the library is located.
This may help.
It happened to me under this situation, I clean the solution and build it again, then many errors like LNK1104 occur.
After trying to restart IIS, I build solution successfully without LNK1104 errors. I do not know why, but restarting IIS takes much more time than normal, so I guess something is used by other IIS worker process.
Just give a shot to see if this magic happens on you.
This question is old and marked solved, but I had a similar problem symptoms with a completely different solution. So just in case anyone else stumbles in here:
It appeared that because I had 2 projects under one solution (a dll and an exe), the building order was mixed (from the output window):
1> Rebuilding project1..
2> Rebuilding project1..
1> file1.cpp
2> file1.cpp
and so on. By the message you copied, it appears you too have more than one project under one solution. One project was looking for the *.lib file that the other build hadn't created yet.
Solution:
Right click on "main" project -> Build Dependencies -> Project Dependencies.. -> Mark which project the main one depends on.

Missing guiddef.h in project

I am new to Visual C++.
I am trying to use library A that in turn uses another library B. When I try to include the header of A, I get an "Error C2061: syntax error : identifier 'GUID'". This error is triggered in a header in library B. When I examine the line that throws the error, the issue is that the header in library B is using a definition found in Guiddef.h, which is a microsoft header.
The problem is that I can't seem to be able to add this header or to create a project that adds it.
I am using Visual Studio 2010 Premium.
Any ideas of what I am doing wrong?
Don't know what you mean by add it to a project or create one that adds it ,but when guiddef.h is on your system and your directories (in common properties) to your MSVC environment are correctly setup ,you just have to add #include <guiddef.h> before the including of lib-headerfiles to your cpp or h files and everything will (should) be fine.
guiddef.h is part of the Windows SDK. If you have VS 2010 Express the SDK is not included, you'll need to download it separately.
If you're using a VS SKU that's 'above' Express, the SDK should already be installed (I'm not sure if you can deselect it or not when in stalling). By default it'll go into:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\
The "Visual Studio Command Prompt" shortcuts that VS installs should set the INCLUDE environment variable appropriately. And a default C++ project should also have the include path setup appropriately, but it can be changed in the project's "VC++ Directories" property (you should check that). If you have a per-project setting here that is wrong, change it there.
However, if your 'IDE-wide' VC++ Directories properties that are inherited by every (or at least most) C++ projects is messed up, follow the instructions on this blog article to fix the global VC++ Directories settings in VS 2010:
http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx
Specifically:
If you open up the Property Manager view to see the property sheets associated with your project, you’ll see that one of the property sheets is named Microsoft.Cpp.Win32.User. This property sheet is actually stored in LocalAppData, just as VCComponents.dat file was, in the directory %LocalAppData%\Microsoft\VisualStudio\10.0. Using the property editor on the property sheet (just right-click on this property sheet node and select Properties...), you can see that you are able to make edits directly to this file. Since all projects, by default, import this property sheet, you are effectively editing the VC++ directories in the same way you were able to do before.
It's possible (though not necessarily true) that you need to include a library as a linker dependency. I'm assuming here that you're already using #include (and have the correct case, with a lowercase 'g')
My suggestion:
Open up the project that has the
header included
open the 'project' menu, and select
'properties'
Under 'configuration properties'
select 'linker'
under 'linker' select 'input'
take a peek at the 'additional
dependencies' field (right at the
top on the right hand side). You
may see some libraries listed there.
Make a note of any libraries
included as dependencies, and repeat
these steps in your 'broken'
project. Add the appropriate libraries to the 'broken' project, if needeed.
You probably don't need the same dependencies in both projects, but if you do need to link a library in the borked project, you should be able to narrow down which one it is you need and include it in the dependency list.
Hope that helps, or at least doesn't steer you too far off course!
edit:
Actually, for some of the headers in the windows API, you might not be able to include them 'alone' (I'm not sure if guiddef.h is one of them), but they should be included as a sub-header of windows.h.