In a C++ project in Visual Studio in:
Project Properties > Linker > Input > Addtional Dependencies
I could write $(MyEnvVar)\folderA\*.lib to include all libraries.
But let's say folderB has many subdirectories which each has a set of header files.
If I want to include them all in one go, in:
Project Properties > C/C++ > General > Addtional Include Directories
I would like to write something like: $(MyEnvVar)\folderB\*\ or $(MyEnvVar)\folderB\*\*\ to go one subdirectory deeper in each folder.
This doesn't seem to work.
Optionally I could do $(MyEnvVar)\folderB\ and in my code I would include each file as #include "name_of_subfolder\name_of_file.h". (This is what I want to avoid.)
Is it possible in one line to include all files in all subfolders of a certain folder?
Related
I have two projects in my C++ MSVC solution:
A static library project
A .exe project that has a reference to the Project #1 (the static library project)
Project #1 has additional include directories, C:/addincdir .
Project #1's header file, p1header.h includes the header hd.h from C:/addincdir.
Project #2 includes p1header.h .
But when I build the solution, I get an error: Project #2 cannot open include file hd.h (cannot find/locate the header file.) I know the solution is to add C:/addincdir to Project #2's additional include directories.
But is there a way for MSVC to automatically add referenced project's additional include directories? Or is there some kind of macro like $(Project1additionalincludedirectories) that includes Project #1's additional include directories and I can add this variable to Project #2's additional include directories?
It just wouldn't be practical to copy-paste every additional include directory from Project #1 to Project #2.
No. There is no way to automatically add the folders.
(step 5 in Walkthrough: Create and use a static library - Use the functionality from the static library in the app)
To include a header file (listed in the additional include folders) you need to use <... >
#include <header.h++>
You can use an environmental variable such as using MORE_INC_DIR and set it to C:/addincdir1;C:/addincdir2;C:/addincdir3; and put $(MORE_INC_DIR) in the additional include directories of both projects.
I'd like to use the image processing package of Dlib (C++ library) in Visual Studio 2013.
I created an empty project and added "dlib-18.16\dlib\all\source.cpp" to my Source Files in the Solution Explorer. Then, I added the path to dlib-18.16 to my Include Directories in VC++ Directories and I also added the path to dlib-18.16\dlib to my Additional Include Directories in C/C++ General of Visual Studio.
I can run the file matrix_ex.cpp which is one of the examples of Dlib, but I can't run the file face_detection_ex.cpp because of the error " Cannot open include file:'type_safe_union/type_safe_union_kernel.h' " which is actually caused by the line #include <dlib/image_processing/frontal_face_detector.h>
How can I resolve this issue? Why the program finds some header files but it can't find the others while they are all located in the same folder?
You need to add the dlib folder itself to the Include Directories in VC++ Directories, you instead added the folder above it.
By extension that would mean your include directive needs to be #include <image_processing/frontal_face_detector.h>.
Let me list a hypothetical example to explain better. You downloaded dlib-18.16.tar.bz2 and extracted it to c:\projects. This creates a folder named c:\projects\dlib-18.16. Within VC++ Directories you added c:\projects\dlib-18.16 to the Include Directories.
However this isn't correct, you should remove that directory and instead add c:\projects\dlib-18.16\dlib as that is the include directory for the project.
That will cause #include <type_safe_union/type_safe_union_kernel.h> to load C:\projects\dlib-18.16\dlib\type_safe_union\type_safe_union_kernel.h as well as similar internal links between files.
I'm working on an existing Visual Studio 12 "Solution" from another team..
In one of its "project"s,, there's a header file that includes a file from another static library projecet..
So Lets say the solution structure looks something like this:
Project A (Static Library Project)
\__ someFile.h
Project B (Static Library Project)
\__ someLibrary.h
In someFile.h,
...
#include "someLibrary.h"
...
and this loads the library successfully.. BUT this is strange because the path to someLibrary.h is NOT SPECIFIED anywhere in Project A's settings!!
I've checked Configuration Properties => VC++ Directories => Include Directories but path to someLibrary.h is NOT specified here..
Since Project A is a static library with NO cpp files (has only header files), It does not have a Configuration Properties => C++ => Additional Include Directory Option at all... (It only has the Librarian option)
And of course someLibrary.h is not in the same directory as someFile.h.
Finally, in Project A's Common Properties, Project B is not referenced either...
So my question is : How the hell does someFile.h know where someLibrary.h is?
How is it including it??
Is there any other places in project settings/etc where additional include directory can be specified..?
UPDATE:
when I right click on the #include statement and click "Open Document 'someLibrary.h'",
I do see a following VS error box:
File 'someLibrary.h' not found in current source file's directory or in build system paths.
Nevertheless,, there is NO build error, and Project A uses someLibrary.h with no problem!!
I have "source" and "include" folders which contain .cpp and .h files respectively for my project.
I have them in the same directory as the project.In the project I include the content of both folders and in the properties add the "include" folder as additional include directory.The project compiles but I can't access any header which is not related to these files via intellisense.For example GL\glew.h headers are included and used in my headers but I can't see those in the headers list when typing #include. Once I create a .cpp file outside "include" or "source" folder all the rest of project includes become visible there again.What do I miss here?
I finally solved this.Here is what was the issue:
It appears that using realtive path in VS2012 like this:
../../../SomeIncludeDir
Wouldn't really work for intellisence .At least for me.
I had to add this in the beginning :
$(ProjectDir)
So it goes like this:
$(ProjectDir)/../../SomeIncludeDir
This way VS can see the included dir ok.
Make sure to set path to the header files in project properties. Adding the headers to the solution explorer does not make them visible to IntelliSense.
Alt+F7 to open Property Pages > Configuration Properties > C/C++ > General > Additional Include Directories
I am currently trying to compile a simple program that includes two header files. I see them in the Solution Explorer, where I included them through "include existing files". However, when I run my program it get the following error.
fatal error C1083: Cannot open include file: 'FileWrite.h': No such file or directory. THe problem is that I see the file included in the Header's folder and in the code I have written:
#include "FileWrite.h"
and then the rest of the program code.
Is there something else needed to do so that the compiler can see the header file and link it to the .cpp file I'm trying to compile?
If you write in your code something like #include "FileWrite.h" you need to make sure compiler can find that file. There are three options:
FileWrite.h should either be in the same directory as your source code file (.cpp) or
Path to that header file should should be listed in project's Properties (in C/C++ -> General -> Additional Include Directories) or
Path could be set in your VisualStudio - add it to Include Files in Tools->Options->Projects and Solutions->VC++ Directories
Which of these options shell be used depends on whether that header originates from this project (1st option) or some other project (any of other two options).
There are two ways to do this.
1) Only for the current project
Select your project -> properties -> C/C++ -> General -> Additional Include Directories -
Include your header file directory.
2) For all projects
Tools -> Options -> VC++ Directories -> Include files - Add the header file directory.
Refrain from using 2, as it would be difficult to figure out dependencies for a project when compiling it on a system different than yours.
When including files the compiler first looks in the current directory (the directory which contains the source .cpp file) then it looks in the additional include directories. If FileWrite.h isn't in the same directory as your source file check the additional included directories.
In the project's property page look at the additional include directories and see if they include the folder in which FileWrite.h is in.
You said the file is in the "headers" folder. This could either mean the headers filter or an actual headers directory on the filesystem. When including a file from your own project you need to specify the path from the file you're including into. So, if you had something like so:
src/main.cpp
include/my_object.h
You would use #include "../include/my_object.h" in main.cpp.
That's for directories. The folders you see in your project are called filters and have absolutely no relation to the directory structure of your project unless you force it to. You need to be paying attention to what the structure looks like in windows explorer to ascertain what path to use in an include statement.