I have a visual studio solution myvs.sln with the following path: c:\dir1\dir2\dir3\myvs\myvs\myvs.sln. I have boost version xxx installed in c:\dir1\dir2\dir3\boostxxx\.
I have in the project->properties->c/c++->general: ../..;../../boostxxx. Inside boost libraries the include files have the following syntax: #include <boost/smart_ptr/shared_ptr>.
My code file myfile.h resides in c:\dir1\dir2\dir3\yy1\myfile.h. In myfile.h I include boost libraries as: #include <boost/shared_ptr.hpp>. I am getting a error which says: c:\dir1\dir2\dir3\yyy1/myfile.h fatal error C1083 cannot open include file boost/shared_ptr.hpp.
The question is what should I do to correct this?
I also notice that the error output the compiler throws has "\" upto dir3 and then changes to "/".
Most probably I do not understand how the relative path is working. Also note that I want to refer to only relative path not absolute paths. Can someone please help? I am in windows platform using c++ visual studio 2010.
Relative paths in the search paths refer to the directory of the file with the #include directive the current directory of the compiler, some simple testing now shows.
"..\.." is going up two levels from your header file the current directory of the compiler instead of from your project directory.
To fix this, explicitly start your include paths in your Visual Studio project directory, as follows (literally):
$(ProjectDir)..\..;$(ProjectDir)..\..\BoostXXX
Regarding forward versus backward slash, use forward slash in your C++ code's #include directives, because that's most portable.
Use either forward or backward slash (but I prefer backwards slash so as to have a single convention) where you're referring to the Windows file system, such as in the setup of include paths.
Related
In Visual Studio Code, I am trying to get a very basic ESP Arduino project to compile.
My includePath entry in c_cpp_properties.json file looks like this:
Inside the 2.7.4 folder, there is a header file pins_arduino.h in the following path:
variants/generic/pins_arduino.h
When I try to compile the project with the following include:
#include "variants/generic/pins_arduino.h"
it does not compile, because:
app:1:31: fatal error: variants/generic/pins_arduino.h: No such file or directory
but when I remove the relative path and rely on the recursion of the includePath it compiles:
#include "pins_arduino.h"
However, the IDE does not recognize any definitions from pins_arduino.h file and marks all of them in red (so even the IDE does not find the definitions, it can compile, because of the recursion ** probably).
Removing the recursion from the includePath did not help, I still get the same compilation error when I use the relative path of the header file.
I am building using Ardiuni Extension (if I understand the concept correctly):
and I have not task.json file.
Why can't I include specific header files using their relative path from sub-folders? Is this some limitation in VS-Code or in C/C++ extension? I do not like using the recursion because I like to specify exactly the header I wanna include using its relative path without including every single folder in the includePath.
I need to include "\boost\iostreams\device\mapped_file.hpp" in my project. I tried:
#include <\boost\iostreams\device\mapped_file.hpp>,
but it couldn't work. Therefore, I used:
#include "C:\path\boost\iostreams\device\mapped_file.hpp".
As a result, the system could find "mapped_file.hpp" file. However, when I build the project, the system complains:
C:\path\boost\iostreams\device\mapped_file.hpp(14): fatal error C1083:
Cannot open include file: 'boost/config.hpp': No such file or directory
This tells me the way I fixed the first error is incorrect.
I have another project downloaded from a repository that uses boost library. This project is already built successfully in my PC. Everything for the boost library in my PC comes from this project, and the header file I need to use is located in "C:\path\boost\iostreams\device\mapped_file.hpp". In this case, how should I add a path or include "\boost\iostreams\device\mapped_file.hpp" to fix my current problem?
Thanks in advance!
I need to include "\boost\iostreams\device\mapped_file.hpp" in my project.
Actually, no, you don't. You might need to include "boost\iostreams\device\mapped_file.hpp" (no leading slash) in your project, but that leading slash will make it impossible for the compiler to find the header file (unless you installed boost to your root directory – rather rare).
In addition, make sure the compiler knows to look in C:\path\ for included headers. As discussed in the comments, this can be done in Visual Studio 2012 via Project properties → C/C++ → General → Additional Include Directories.
I was trying to re-use an available source code for my own project, it can be found here:
https://github.com/TadasBaltrusaitis/OpenFace
I tried compiling project FeatureExtraction of the original code, everything was fine. Then I created a new empty project and added the following #include:
#include "LandmarkCoreIncludes.h"
#include <Face_utils.h>
#include <FaceAnalyser.h>
#include <GazeEstimation.h>
These are exactly the same as in project FeatureExtraction in the provided source code. I've already changed the additional include directories in C/C++ general tab into:
$(SolutionDir)\lib\local\FaceAnalyser\include
$(SolutionDir)\lib\local\LandmarkDetector\include
However, it still gave me "cannot open source file error".
Update: If I put the absolute path of the header file directly to the code it is OK, however if I put the absolute path to the Additional Include Directories, the error remained.
Use #include "header.h" instead of the one with diamonds (< and >) which looks in another directory.
After that, check if the header files really are in these directories. If they are, you should check the $(SolutionDir) ( I don't use a '\' after the $(SolutionDir) but it may work out as well).
Try to locate and delete the .suo file and restart VS
Looks like I had same "bug" as mentioned in this post here:
Visual Studio does not honor include directories
After having changed the Additional Include Directories for all platforms instead, the code was compiled without any errors.
could you please help me out by answering my following question about the Visual Studio include behavior?
I create a new C++ Project, which references an already existing one, whose source files should not be altered. I end up with the following file
structure:
-MyProject
+---MyProject.sln
+---MyProject.vcxproj
+---MyProject.cpp
+---CommonHeader.h
-ExistingProject
+---project
+---+---ExistingProject.vcxproj
+---source
+---+---ExistingProject1.h
+---+---ExistingProject2.h
+---+---ExistingProject1.c
+---+---ExistingProject2.c
At the beginning, i could not even compile the ExistingProject. Within the ExistingProject1.c, the following include statement exists:
#include <ExistingProject1.h>
From here i learned, that in case of the bracket-includes, Visual Studio does not look for the Header within the same directory as the file that contains the include statement. So my first question would be:
1) Is it true, that i have to add the "../source/"-Directory to the Include Directories of the ExistingProject.vcxproj, although the Header files are already added to the visual Studio project?
To use the structures and functions of the ExistingProject, i have to include the ExistingProject2.h into my MyProject.cpp. But within the ExistingProject2.h, the same include Statement
#include <ExistingProject1.h>
exists. This leads to my second question:
2) Is it true, that i have to add the "../ExistingProject/source/-Directory to the Include Directories of MyProject.vcxproj project as well?
And now comes the really strange problem. If a certain define is set, which has to be set within MyProject, the ExistingProject2.h also includes an external header file via
#include <CommonHeader.h>
Which has to be defined by the dependent project. This leads to my last question:
3) Is it true, that i have only the following two options to compile with this external header file?
I have to copy my CommonHeader.h into the "ExistingProject\source\"-Directory during checkout.
I have to add the "."-Directory to the Include Directories of MyProject.vcxproj project and i have to add the "../../MyProject/"-Directory to the Include Directories of ExistingProject.vcxproj.
The second option just makes no sense. Is the first one really my only option to deal with this bracket-form include of an external header file?
And: Shouldn't be at least the location, next to the vcxproj file, be within the include directories of a header file, which is used within that project?
Sorry for the stupid spelling. I am a really bad explainer.
Wish you all a nice weekend.
When you put #include <header.h> - Visual Studio will search for it in all specified include paths in project settings, this includes default paths, where Windows SDK and standard library resides. See this screenshot, as example:
If you put C:\path1\path2 to include directory, you might end up using #include <..\path1.h>
In case of #include "quotes.h" - Visual studio will search for files only in project directory, where you store your files. If you put additional files in some sub-folders in project - you always need to specify relative path (like #include "subfolder\header.h").
Let me know, if you need further clarification on this.
This is the exact definition of how Visual Studio uses bracket includes (<>) versus quote includes (""): https://learn.microsoft.com/en-us/cpp/preprocessor/hash-include-directive-c-cpp .
Summary: Brackets <> will stick strictly to the "include directories" settings. Quotes "" will also do "include directories", but will first search local project directories.
I am trying to compile the Scintilla control with MSVC++ 2010 Express Edition, and it's quite painful getting it to work right because I need a bunch of files. When compiling SString.h, I noticed this:
#include <crtdll/stddef.h>
I am no C++ programmer, but I do understand what
#include <xxx.h>
means, but what does the the that include mean? I get the following error with it:
Error 1 error C1083: Cannot open include file: 'crtdll/stddef.h': No such file or directory f\scintilla\lexers\sstring.h 44
Any help on how I could fix it would be appreciated.
If I am not mistaken, that is just a relative path. In other words, Visual Studio will look for stddef.h in the crtdll subdirectory of, probably, the root directory of the project.
By using the preceding function, you are summoning, and subsequently inserting a header file into your current source code.
In the case of #include <crtdll/stddef.h> you will be inserting the stddef.h header file from the crtdll directory (which should be a child folder defined in your compiler as the holding pen for header files) during the compilation and linking of your program.
By inserting the stddef.h header file into your source you are giving your program the capability to wield NULL pointer constants, which are exceedingly useful in some of the more advanced programs you may or may not have come across.
Good luck with your program!
I am no C++ programmer, but I do understand what
are you sure?
include with <> searches the include paths for the specified file and copies the content the content of that file in your .cpp.
So you are just missing the crtdll/stddef.h file, however stddef.h actually belongs to the C standardlibrary so you might replace it with #include in C or #include in C++
The easiest way would be to check your include directories. crtdll is the C standard library provided by msvc, so maybe you have to add the parent folder of your standard library include directory
This means that stddef.h needs to be included from the crtdll folder.
You need to check your include directories for Visual C++ projects to see that which are the default directories from where Visual Studio looks up for header files.
To fix this error, see that at which path have you installed the Scintilla control. The crtdll folder will be there most probably. And then, add this folder to your visual studio include directories.
You can set it in the following project properties dialog:
Here http://i56.tinypic.com/2zo9guh.jpg