Storing a C++ header file globally in Windows - c++

I'm using a library for image processing called Cimg. The library is stored in a single .h file (cimg.h).
I need to create several Visual Studio solutions(one solution for each exercise).
Where can I put this file globally so that I don't have to copy it to the Visual Studio solution each time?

You can put your header file anywhere you want, then add that folder as additional include directory for your visual studio project: Right click your project in the solution explorer, then:
Configuration properties->C/C++->General->Additional Include Directories
Just add the path there, and you can simply include CImg.h by:
#include <CImg.h>

Related

#include <winsqlite/winsqlite3.h> works in one project, not another

From Visual Studio 2017 I created a console application to test Sqlite. The first line I put in my main file was
#include <winsqlite/winsqlite3.h>
This caused no problem (the location was found). But I tried adding this include to a source file I had obtained by migrating a legacy project to VC++ 2017. This time the include line causes an error.
I suspect I should look at
$(VC_IncludePath);$(WindowsSDK_IncludePath);
however, I do not know how I can find out what's in the macros VC_IncludePath and WindowsSDK_IncludePath, let alone change them.
Could there be any other explanation?
>>however, I do not know how I can find out what's in the macros VC_IncludePath and WindowsSDK_IncludePath, let alone change them.
In Visual Studio, open Project->Properties->VC++ Directories->Include Directories->edit->Macros, Then you can check the content of these Macros.
If you need to use a three-party library in Visual Studio, you generally need to add three places in the property page. I will show in the picture below.
include is the path of .h file and library is the path of .lib file, and you should also fill the name of .lib file in the third edit box(additional dependencies). In your case, this third-party library seems has only .h file, so just add the path of .h file to the first edit box. Or simply put the file directly in your project's root directory and add it to your project in Visual Studio, then include it.

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.

visual studio 2012 adding new header file

In Visual Studio 2012 (C++ environment), for a Win32 console application, I need to include a new header file to my project. I tried copying the files in the project's location but that is of no help. The file is iGraphics.h and it is shown in the header files list but does not compile. What should be the correct approach?
You should add the path to that header to the additional include directories under C/C++ in your project settings. Afterwards, just #include "iGraphics.h" where you need it.
Don't just move header files around, and don't add existing headers to your project for no good reason. This way, you can easily change versions by just specifying a different folder.
The easiest way to do this is:
Right click on the header file (to be included) in the Solution explorer.
General->"Excluded from the build"
Select "No" from the drop down list
Click "OK".
In VS2012, just using '"' instead of '<>' around the header file in include also works.
Put the file in the right place in the file system (like you did). Then right-click your project in the solution explorer and use Add > Existing Item to add it to your project.
If you don't want to move your file (which you probably should not), see Luchian's answer on how to add the include directory to the include folders.

Creating a C++ visual studio project based on existing files

I've never worked with C++ or C. I'm trying to create a Visual studio project based on existing files which can be found here: example1.cpp together with the resources. As you can see this is example code of a book for OpenGl. I have opengl and glut present on my computer and they work ( tested it).
Based on the files mentioned above a created an empty C++ project in visual studio 2012 (i also have other versions installed if you can provide a solution in 2010 or so). I included the header files & the source file. Though I still get the following in my IDE:
with errors such as:
cannot open source file "Angle.h"
( Though the file is present in the project)
Can anyone tell me how I get these files to compile and run ?
Make sure that the file angel.h it's in the same path that the .cpp file.
Header files need to be in same directory with source files in order to use #include with quotes.
#include "header.h"
In other words Angel.h must be in same directory with example1.cpp.
However,you can add spesicific paths to your project from Project Settings>VC++ Directories and include header files which exists in those paths using
#include <header.h>

Copying C++ API header files to a common directory

I have a Visual Studio 2008 solution comprised of several projects. Only some header files in each project represents API to the library built from the project.
Is there a way in Visual Studio to copy the files to a common directory prior compilation?
(I want to do it in order prevent including unintentionally header file I'm not supposed to)
Thanks
Dima
Yes, on the project menu, select properties->configuration properties->build events->pre-build event. In the command line section you can enter a copy command with your source and destination paths. You may find the $solutiondir macro useful when enterting your paths.
You can run a script before compilation to do this (see pre-build step) but I don't think this is what you are asking.
Do you mean how can you have header files in another directory used by several projectS? Simply add that directory to the "Additional Include Directories" field in project settings-C++ ->General
>