On Visual Studio I see one can set path of i.e. util\util.h on that side panel, right-click the project then
Properties > C/C++ > General > ...
I add util directory there and then I can do #include "util.h" on a file from another directory, instead of providing the full path util\util.h.
Besides the approach descrived, is there another way which also will allow me to #include "util.h" (not provide the full path)?
I'm not familiar with Visual Studio at all.
Within the the Visual Studio Dialog you describe under: Properties > C/C++ > General > if you select the drop down icon and select "Edit" you will see a button titled "Macros" this provides a list of available Macros for use on the "Additional Include Directories" line. Likely you will want to use: "$(ProjectDir)\util". $(ProjectDir) is the directory that your project file is sitting in.
Let say you have created a project names 'Project1'. Then there will be a 'Project1.vcxproj' file which stores the settings for the project. Visual studio also looks for any files (source or header) in the folder starting with where this project file is located. Use the relative path with respect to where this file is located.
Let say your directory structure is as follows:
-Project\
--Project1\
---Project1.vcxproj
-Source\
--header.h
Use include path as
#include "..\Source\header.h"
I am trying to compile a project, but it looks for includes in the wrong folder or for some other reason cant find winres.h.
I tried adding the path to it (C:\Program Files (x86)\Windows Kits\8.0\Include\um) everywhere but it doesn't work.
My VC++ include derictories path looks like this:
$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Windows Kits\8.0\Include;
My C/C++ Additional Include Directories path looks like this:
../../include;../../src/libpocketsphinx;../../../sphinxbase/include;../../../sphinxbase/include/win32;C:\Program Files (x86)\Windows Kits\8.0\Include;%(AdditionalIncludeDirectories)
The error is:
pocketsphinx.rc(10): fatal error RC1015: cannot open include file 'winres.h'.
How do I change the include path?
I would post the images illustrating but I do not have enough reputation points. To change the includes of a project, follow these steps:
1) Open visual studio.
2) Open your projects.
3) Open the drop down menu by right-clicking your project in the solution explorer.
4) Click on Properties.
Now there are two places to change includes:
1) Click on VC++ Includes.
2) Add an includes directory to the field "Include Directories".
Or
1) Click on C/C++>General.
2) Add an includes director to the field "Additional Include Directories".
If this is just for the current project, use the second means of adding. Then of course, click OK or Apply.
For future reference, I suggest going through some of the VS tutorials. This would be covered there.
I am using Visual Studio 2012 and trying to import header files in the project, but have been failing miserably. Here is what I have tried to do:
#include "gevents.h"
#include "gobjects.h"
#include "gwindow.h"
int main(){
int x=1;
return 0;
}
I have added these three header files in the project location:
C:\Users\Shaby\Documents\Visual Studio 2012\Projects\ConsoleApplication39
In addition, I have also gone to Project properties ->Configuration Propertues -> C/C++ ->General and included the above path location in "Additional Include Directories" but this had yielded nothing. Instead, I am getting the following error:
Unable to start program C:\Users\Shaby\Documents\Visual Studio 2012\Projects\ConsoleApplication39\Debug\ConsoleApplication39.exe The system cannot find the file specified
#Usman Khan ,
I have one solution for your problem.In Solution Explorer Window (if not opened then press Ctrl+Alt+l) you can see you project name.Right click on it and than Add > Existing Item. Now select your header files which you want to include & press Add. Done :) .
why are you making it complex, just keep it simple.After creating your project. Open solution explorer. Under your project name you would see a folder "header files" , add your header files in it (your header files should have ".h" extension) and then to use them include them in your source files
I have recently gone from Code::Blocks to Visual Studio, and in Code::Blocks one could just add a class and then include it straight away. However, whenever I do the same in Visual Studio with the following statement:
#include "includedFile.h"
or
#include "include/includedFile.h"
It doesn't work and instead I get the error:
cannot open include file: 'includedFile.h'; no such file or directory.
Is there some box or setting that I have to tick? Or do I have to add each header as a dependency manually?
Here is the code for the class in question:
Public.h:
#pragma once
class Public
{
public:
static const int SCREEN_WIDTH=1000;
static const int SCREEN_HEIGHT=1250;
Public(void);
~Public(void);
};
Public.cpp:
#include "Public.h"
Public::Public(void)
{
}
Public::~Public(void)
{
}
How it is being included:
#include "Public.h"
I had this same issue going from e.g gcc to visual studio for C programming. Make sure your include file is actually in the directory -- not just shown in the VS project tree. For me in other languages copying into a folder in the project tree would indeed move the file in. With Visual Studio 2010, pasting into "Header Files" was NOT putting the .h file there.
Please check your actual directory for the presence of the include file. Putting it into the "header files" folder in project/solution explorer was not enough.
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
And be sure that your Configuration and Platform are the active ones. Example: Configuration: Active(Debug) Platform: Active(Win32).
You need to set the path for the preprocessor to search for these include files, if they are not in the project folder.
You can set the path in VC++ Directories, or in Additional Include Directories. Both are found in project settings.
By default, Visual Studio searches for headers in the folder where your project is ($ProjectDir) and in the default standard libraries directories. If you need to include something that is not placed in your project directory, you need to add the path to the folder to include:
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
You can, also, as suggested by Chris Olen, add the path to VC++ Directories field.
I found this post because I was having the same error in Microsoft Visual C++. (Though it seems it's cause was a little different, than the above posted question.)
I had placed the file, I was trying to include, in the same directory, but it still could not be found.
My include looked like this: #include <ftdi.h>
But When I changed it to this: #include "ftdi.h" then it found it.
If your problem is still there it's certainly because you are trying to compile a different version from your current settings.
For example if you set your Additional Include Directories in Debug x64, be sure that you are compiling with the same configuration.
Check this: Build > Configuration Manager... > There is problably something like this in your active solution configuration: Debug x86 (Win32) platform.
For me, it helped to link the projects current directory as such:
In the properties -> C++ -> General window, instead of linking the path to the file in "additional include directories". Put "." and uncheck "inheret from parent or project defaults".
Hope this helps.
I tried the other answers here as well, but my problem had nothing to do with the include paths or files missing incorrect #includes. I had two configurations, each set to the exact same include directories. One configuration could resolve the includes, the other could not.
After selecting my project and going to Project -> Properties, I selected both configurations through the Configuration dropdown -> Multiple Configurations... option. Comparing the two I found that C/C++ -> Language -> Conformance Mode was different. The "incorrect" configuration had a value of Default for some reason, and switching it to Yes or No allowed the paths to be resolved.
TL;DR: If you have one configuration with the same include directories but the other isn't finding the files, I suggest to try comparing the configurations.
If you've tried the other answers and your include file still can't be found, here are some additional debugging steps and sanity-checks:
Ensure that you are building to a platform that is supported by your code. (If not, consider removing this platform as a target)
Verify that the filename/path is correct. Modify your source code to #include the whole absolute path of the header file instead, and see if the file can be found now. If not, copy-paste the path from your source code into a command line to validate that the file exists at that full path with no typos. Open the header file to ensure you have read access. (Change the source code back when done.)
If you've already added the path to Additional Include Directories, try clicking the drop-down combo box for Additional Include Directories, and select <Edit...>. This will show you evaluated values of paths. (If it does not show the correct evaluated values, variables in your path might not be set. Click Macros>> to see variables.) Copy-paste the evaluated path into windows explorer to validate that the path exists.
Create a new empty C++ "Windows Console Application" project. Set just the one Include Directory, and #include just the one file in your main.cpp, and see if that builds.
I need to build this c++ project.
its failing on the line
#include <wkhtmltox/image.h>
#include <wkhtmltox/pdf.h>
fatal error C1083: Cannot open include file: 'wkhtmltox/image.h': No such file or directory
fatal error C1083: Cannot open include file: 'wkhtmltox/pdf.h': No such file or directory
clearly its not finding the file. i have the file on disk but just need to point the project at it some how.
how do i set the project up so it can see this file?
Also If its not already clear, i'm a complete novice at c++
edit:
i'm trying to build this: https://github.com/antialize/wkhtmltopdf-bindings/tree/master/wkhtmltoxcom/
Visual Studio 2008
Goto "Tools->Options->Projects and Solutions" then select "VC++ directories" and select "Include files" in the combo box at top right corner. Specify the directory where the file is present. That should solve the problem.
Or if you want to customize it per project, hit Alt F7 or go to Project -> Properties -> C++ -> General, and set the include directories.