How to configure addition library folders for Visual Studio 2013? - c++

I have legacy, non Visual Studio project. Its structure is:
-root_folder
-root_folder/folder1
-root_folder/folder1/main.cpp
-root_folder/folder1/fun.cpp
-root_folder/folder2
-root_folder/folder2/bar.cpp
-root_folder/folder2/foo.h
.... many different folders
I work with project under folder1.
root_folder/folder1/main.cpp:
#include <folder2/foo.h>
....
I have the error: Error can not open source file "folder2/foo.h>".
Of course, I added the folder root_folder in Project -> properties -> c/c++ section -> additional include directories.
I cannot change this source code, so I need right configure project settings.
Also, I have one more problem. Visual studio does not show my folders structure. It just show folder Source Files, which contains all thousands files.

Visual Studio looks in "VC++ Directories" -> "Include Directories" for the include files specified in angle brackets.
You need to add you path there:
https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k%28VS.ToolsOptionsPages.Projects.VCDirectories%29&rd=true
P.S. Just noticed that this answer was given earlier, and rejected.
However, it most certainly works; tested with VS2013.

Related

Install geos on Visual Studio using VCPKG [duplicate]

I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.
Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?
Are there special directories?
Visual Studio looks for headers in this order:
In the current source directory.
In the Additional Include Directories in the project properties (Project -> [project name] Properties, under C/C++ | General).
In the Visual Studio C++ Include directories under Tools → Options → Projects and Solutions → VC++ Directories.
In new versions of Visual Studio (2015+) the above option is deprecated and a list of default include directories is available at Project Properties → Configuration → VC++ Directories
In your case, add the directory that the header is to the project properties (Project Properties → Configuration → C/C++ → General → Additional Include Directories).
Actually, on my windows 10 with visual studio 2017 community, the path of the C++ header are:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt
The 1st contains standard C++ headers such as <iostream>, <algorithm>. The 2nd contains old C headers such as <stdio.h>, <string.h>. The version number can be different based on your software.
If the project came with a Visual Studio project file, then that should already be configured to find the headers for you. If not, you'll have to add the include file directory to the project settings by right-clicking the project and selecting Properties, clicking on "C/C++", and adding the directory containing the include files to the "Additional Include Directories" edit box.
There seems to be a bug in Visual Studio 2015 community. For a 64-bit project, the include folder isn't found unless it's in the win32 bit configuration Additional Include Folders list.
There exists a newer question what is hitting the problem better asking How do include paths work in Visual Studio?
There is getting revealed the way to do it in the newer versions of VisualStudio
in the current project only (as the question is set here too) as well as
for every new project as default
The second is the what the answer of Steve Wilkinson above explains, what is, as he supposed himself, not the what Microsoft would recommend.
To say it the shortway here: do it, but do it in the User-Directory at
C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0
in the XML-file
Microsoft.Cpp.Win32.user.props
and/or
Microsoft.Cpp.x64.user.props
and not in the C:\program files - directory, where the unmodified Factory-File of Microsoft is expected to reside.
Then you do it the way as VisualStudio is doing it too and everything is regular.
For more info why to do it alike, see my answer there.
Tried to add this as a comment to Rob Prouse's posting, but the lack of formatting made it unintelligible.
In Visual Studio 2010, the "Tools | Options | Projects and Solutions | VC++ Directories" dialog reports that "VC++ Directories editing in Tools > Options has been deprecated", proposing that you use the rather counter-intuitive Property Manager.
If you really, really want to update the default $(IncludePath), you have to hack the appropriate entry in one of the XML files:
\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props
or
\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\PlatformToolsets\v100\Microsoft.Cpp.X64.v100.props
(Probably not Microsoft-recommended.)
It looks for files in the directory mentioned in options" cwd, you can include all sub directory under a path as shown below.
it will create a single output file.
it will compile all files together in the directory specified in cwd
project Structure:
moduelTest
-header_files
- util.h
-source_files
- util.c
- main.c

Boost C++ Libaries in Visual Studio 2017 C++ Project - "Cannot open include file"

I'm trying to add the Boost C++ Libraries to my C++ project created with Visual Studio 2017.
I have followed the instructions here.
When that didn't work I tried the advice in this post. Neither solutions worked for me.
What I have done:
Downloaded boost_1_69_0-msvc-14.1-64.exe from this precompiled boost libraries page
Installed to D:\local\boost_1_69_0
In my project I added D:\local\boost_1_69_0 to Properties > VC++ Directories > Include Directories and added D:\local\boost_1_69_0\lib64-msvc-14.1 to Properties > VC++ Directories > Library Directories
I have my project set to x64 and the above settings were set in the x64 configuration
When I try to build my project I get this error:
Error C1083 Cannot open include file: 'boost/regex.hpp': No such file or directory
Which points to this line of code in one of my .cpp files:
#include <boost/regex.hpp>
Please go to D:\local\boost_1_69_0 folder and see if you have a sub-folder named include in there. If you do, then instead of D:\local\boost_1_69_0 you need to set D:\local\boost_1_69_0\include in Properties > VC++ Directories > Include Directories
In other words, try to find the file you are including on your hard drive. Look at the full path to the file. Compare that full path with the path you added to the list of include directories (Properties > VC++ Directories > Include Directories) concatenated with the relative path you provided just before the filename in your include directive (boost). See if the two are the same.
If that does not help, then make sure you changed list of include directories for the same build configuration as you are attempting to build (if you build Debug, make sure you changed configuration for Debug too). Since VS 2015 IDE stopped making sure the two are selected in sync, which is annoying.
If your files are copied, then you have to compile the regular library.... If the same version of the compiler copies the machine.
Found out it was failing because I had included the same .cpp file which has the boost include into my unit test project which did NOT have the Include/Library folders set. The settings in my original question work now.

Cannot open source file in visual studio 2015

I am trying to compile OBS studio with this tutorial in windows using Visual Studio Community 2015. I have created a project in visual studio and copied the entire git repo into the project by dragging the files into the solution explorer. This project has dependencies on libav, x264, and curl. They are given as .lib, .dll, and header files.
The problem is I keep getting "cannot open source file". I have the the header files in a separate folder from the dll's and lib's (dll and lib are in the same folder). Under the project settings->VC++ Directories I added the include directory, and also added the library directory. Then I added the lib's specifically under Linker->input->additional Dependencies. Then I added the directory that contains the .dll files to the environment variable PATH.
After all this, I still keep getting the same error, as well as a few other errors. Here is a screen shot of one source file that has the issue.
These are my settings.
For the path, I have tried with and without the trailing forward slash.
EDIT:
Use the C/C++ settings instead of VC++ settings for additional include directories.
What is probably holding you up is that those folder icons in the VS sidebar are not actually related to the file system. They are filters and don't change depending on the actual directory.
This is another explanation for Drop's suggestion -- check to see if the files are really where you think they are.
In my case I already added the include libraries but that was not enough. The error went away once I switched the configuration from x86 to x64 in Project Properties.

What is the diff b/w Includes in VC++ Directories options and Additional include directories in C++ -> General in Visual Studio

I tried adding the include directories in the VC++ Directories -> Include Directories option in Tools -> Options but when compiling I get error - "Can't find file or directory" . Once I add to the Project properties -> Configuration properties -> C++ -> General -> Additional include directories , I could compile successfully.
So why does Visual Studio have a Include Directories option. Why is it used for ?
(I'm using Visual studio 2010 Beta 1 )
Visual Studio team recently explained differences of VS 2010 regarding include directories to earlier versions in their blog.
You should find your answer here: http://blogs.msdn.com/vsproject/archive/2009/07/07/vc-directories.aspx
Include directory under tools is common for all projects. This is where your includes for the Windows SDK is listed which is almost used by all the projects. The include directory under C++ tab is specific to that project. This is where you list all your custom project include files.
I think you mean "VC++ Directories" in Tools->Options->Projects.
The directories listed here are visible in the entire VS environment (common to all projects). That is it consists of the path to use when searching for executable files while building a VC++ project.
So ,
you cannot specify paths relative to
the location of project files. One
should avoid this option IMHO.
Listing the paths in project setting
also makes it more configurable as
these directiories are considered
when compiling through command-line
also. Most major projects have
automated builds through command-line,
so they would fail to build if the
directories are not listed in the
project properties.
http://msdn.microsoft.com/en-us/library/t8096eby(VS.100).aspx
Please refer to this document.

Where does Visual Studio look for C++ header files?

I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.
Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?
Are there special directories?
Visual Studio looks for headers in this order:
In the current source directory.
In the Additional Include Directories in the project properties (Project -> [project name] Properties, under C/C++ | General).
In the Visual Studio C++ Include directories under Tools → Options → Projects and Solutions → VC++ Directories.
In new versions of Visual Studio (2015+) the above option is deprecated and a list of default include directories is available at Project Properties → Configuration → VC++ Directories
In your case, add the directory that the header is to the project properties (Project Properties → Configuration → C/C++ → General → Additional Include Directories).
Actually, on my windows 10 with visual studio 2017 community, the path of the C++ header are:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt
The 1st contains standard C++ headers such as <iostream>, <algorithm>. The 2nd contains old C headers such as <stdio.h>, <string.h>. The version number can be different based on your software.
If the project came with a Visual Studio project file, then that should already be configured to find the headers for you. If not, you'll have to add the include file directory to the project settings by right-clicking the project and selecting Properties, clicking on "C/C++", and adding the directory containing the include files to the "Additional Include Directories" edit box.
There seems to be a bug in Visual Studio 2015 community. For a 64-bit project, the include folder isn't found unless it's in the win32 bit configuration Additional Include Folders list.
There exists a newer question what is hitting the problem better asking How do include paths work in Visual Studio?
There is getting revealed the way to do it in the newer versions of VisualStudio
in the current project only (as the question is set here too) as well as
for every new project as default
The second is the what the answer of Steve Wilkinson above explains, what is, as he supposed himself, not the what Microsoft would recommend.
To say it the shortway here: do it, but do it in the User-Directory at
C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0
in the XML-file
Microsoft.Cpp.Win32.user.props
and/or
Microsoft.Cpp.x64.user.props
and not in the C:\program files - directory, where the unmodified Factory-File of Microsoft is expected to reside.
Then you do it the way as VisualStudio is doing it too and everything is regular.
For more info why to do it alike, see my answer there.
Tried to add this as a comment to Rob Prouse's posting, but the lack of formatting made it unintelligible.
In Visual Studio 2010, the "Tools | Options | Projects and Solutions | VC++ Directories" dialog reports that "VC++ Directories editing in Tools > Options has been deprecated", proposing that you use the rather counter-intuitive Property Manager.
If you really, really want to update the default $(IncludePath), you have to hack the appropriate entry in one of the XML files:
\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props
or
\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\PlatformToolsets\v100\Microsoft.Cpp.X64.v100.props
(Probably not Microsoft-recommended.)
It looks for files in the directory mentioned in options" cwd, you can include all sub directory under a path as shown below.
it will create a single output file.
it will compile all files together in the directory specified in cwd
project Structure:
moduelTest
-header_files
- util.h
-source_files
- util.c
- main.c