VSCode: How to add include path of project subDirectory? - c++

I just started using VSCode on linux Ubuntu environment and for past one day trying to include some header files from a sub-Directory (the project screen shot is shown below).
I have tired adding the header file path in include path but showing error.(Image below)
I also tired by provided complete path e.g. /home/user/Work/Cpp_Test_Project/OpenFace/FaceAnalyser/include/ still it couldn't find the header file.
Also, If I try to include the header with local path e.g.
#include <OpenFace/LandmarkDetector/LandmarkCoreIncludes.h
then all the internally linked header file doesn't work.
any help will be highly appreciated.

The c_cpp_properties.json file is for configuring IntelliSense. The compiler you are using does not read from this file, so you will need to configure the include path for that separately. From what you have posted, it is unclear how you have set up your build.

Related

Cannot open include file even when given the right path

I've been testing some stuff in Visual Studio after some time not working with VS, And I ran into a problem where I include a file and I get this error:
Cannot open include file 'spdlog/spdlog.h': No such file or directory
but I have the right path, in Project settings I have the right path set as an additional Include directory and the file is there. but the Thing is, when I take the file and move it one directory up and change the include path so that it now points one directory up (where the file is now) it suddenly works. Example:
File Path: Project/lib/spdlog/spdlog.h
Include directory: Project/lib
this Works
File Path: Project/lib/spdlog/spdlog/spdlog.h
Include directory: Project/lib/spdlog
This doesn't work
I don't want to include the lib directory since I have more libraries in it and it would just mess some stuff up, so I want to include every library (like spdlog for instance) separately. Does anyone know what might be causing the issue ? Also the error isn't shown when writing the code only when I try to build the Project.
Maybe you are missing spdlog library.
I suggest you check out this issue.
For debian-like distros you should be able to download it via apt-get: apt-get install libspdlog-dev.

IAR C Preprocessor include directories

I've been asked to make a small mod to some software that was written back in the mid naughties on IAR Embedded Workbench v3.3
I have had the original source files copied from an old machine to one I have been given for the task.
For the moment I am simply trying to get the software compiling. It took me a while to realise, or at least I thought I'd realised, that the reason it couldn't open various header files was that, incredibly, all the include paths were absolute, not relative.
So, I changed all the paths to be $PROJ_DIR$ relative, but then started to get different files that couldn't be opened. Then realised that the machine they gave me just happened to have a very similar directory structure to the original machine used and, amazingly, had quite a few of the same files in the directory structure of this machine I'm using as was on the machine used to compile the code originally.
I then thought, OK, I'll just check I have got my relative paths correct by choosing one of the header files it was complaining about not finding and putting, in the Preprocessor tab, an absolute path to the directory on this machine I'm using that contained the header file it wanted. However, that still wouldn't find the header file!
Finally, I put an absolute path in the c file to point to the desired header file.
#include "C:\absolute__Path\stdtyp.h"
And it compiled.
To confirm:
Putting C:\absolute__Path
in the Project | Options | C/C++ compiler | Preprocessor tab will not work if I just have:
#include "stdtyp.h"
in the c file.
I have used IAR in the past - not that much - but I have used it and I was sure that's where you set your include directories. So, am I wrong, or can there be something else that is overriding that path in the Preprocessor tab as described above?
Edit: I'm not wrong, after having slept on it, I decided to create a new project with random directories, subdirectories and header files. Sure enough, if I set and remove $PROJ_DIR$ referenced paths in the preprocessor tab, the new project compiles, then doesn't. So, there must be something, presumably in the ewp file that is borking it.
It turns out you can override the paths on an individual file by file basis. So, the rogue files had the paths overridden and had absolute paths.
Right click on the file in EW and select Options.
That then for most file shows a load of greyed out boxes. What I'd failed to do was thoroughly check all files. The few I'd randomly checked were greyed out, but some files had their properties overridden here with different (and absolute) paths put there.
At least now the project can be easily copied between machines having used relative paths.

Why doesn't Xcode6 see included header files

I'm trying to build opencv2 as a universal framework. I am systematically removing the files/folders that I do not need. But I am running into this issue where the include files are not found. See the image below:
The following image clearly shows that the file is indeed there.
One of the contractors working with us said he had put the include files into the same directory as the source files and rename them according to their file structure but using "." instead of "/" as shown below:
But that means that I must go through all of the files that include files and change the include statement to use "." instead of "/". REALLY?
Is this true? Or do we have a configuration set wrong?
You need to setup search paths for your target in Build Settings->Search Paths->Header search paths.

Eclipse C++ including header file from my source folder

I'm pretty new to C++ and Eclipse in general so I apologise if I'm missing something fairly obvious.
The problem I'm having is that I'm trying to include a header file in one of my source files but they're in different folders in my project directory. I have no idea how I should be including them. I've uploaded an image showing my problem with the header file I want to include highlighted.
If someone could tell me what '#include' statement I should be using them that would be brilliant.
Thanks!
There are a couple of different options to make this work. Simplest is to change the #include to
#include "../Statistics/Statistics.h"
This will work without any other modifications. However, if you move either file, or somehow change the relative path between the two, this will break.
Alternately, you can add the path to the Statistics folder to your compiler's include file search path. Right click on the project name, select Properties -> C/C++ Build -> Settings and then find the includes files path option for your compiler. For g++, it is -I<path/to/include/folder>. Adding this will make the #include statement work as you currently have it.
A very similar option to the second one is to add the path to the src folder (instead of the Statistics folder) to the includes search path. In this case, you'll have to change the statement to
#include "Statistics/Statistics.h"
When you create subfolders in your src folder then each cpp file is compiled in that folder it is located in. Thus, any "" includes need to specify the relative path to get from that folder to another.
In your case, to get from inside the FileInOut folder you need to go back one level and then into the Statistics folder
eg
#include "../Statistics/Statistics.h"
Another alternative is, if you are keeping your includes in your src directory, to add the src directory to the include path. Now when you include you need only specify the path from the src root.
eg.
#include "Statistics/Statistics.h"

xcode includes of header files

I am trying to compile a sample project for a browser plugin (http://pushingtheweb.com/2010/06/boilerplate-for-a-npapi-plugin/) using xcode 3.2.6 on Snow Leopard.
I have never used xcode before.
When I try to build I get an error with an include (AE/AERegistry.h: No such file or directory)
When I click on the file it takes me to the header file AE.h (which is in folder /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers) and has the lines:
ifndef __AEREGISTRY__
include <AE/AERegistry.h>
endif
Firstly I dont know how to find out why AE.h is included in the build as I cant see it "included" anywhere.
Secondly why cant it find AERegistry.h which is in four separate locations on the computer?
I manually added one of the folders to the Header paths but it made no difference.
Why is it AE/AEReistry when it is not in a folder AE?
Thanks for any help
George
You'll have to go into the build settings, find "compiler flags"(CFLAGS), and add something like:
-I/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers
And then do:
#include <AERegistry.h>