Visual Studio 2012 Error: Cannot open source file - c++

I have source code (header and source files)of a library. I need to include the source code in my existing project. For that purpose i have copied the entire library source code directory into visual studio project folder then i included that directory to VS by using include to project option. Fine.
There is a header file say "x.h" in the library source code directory which defines some macros, and there are some other header files say "y.h" and "z.h" which are using those macros defined in "x.h". But visual studio is not recognising those macros at all when i included those ("y.h" and "z.h") header files in my main class. Visual Studio generates the error "Cannot open this source file".
Actually "y.h" and "z.h" can not find macros defined in "x.h". How to solve this error?
Is there some kind of setting need in the project properties?
My second question is that how to include some programming files in my project correctly so that i can use that library functionality correctly? I have also Include the header directories in configuration properties > VC++ Diectories > Include Directories.
Third question is that is there a way in which i don't have to include the source code to my project? remember i don't have .lib file or .dll file of that library and i cannot compile that library also.

Have you add
#include <x.h>
or
#include "x.h"
Are library files in a sub-folder? if Yes try
#include ".\subfoldername\x.h"

Related

How to include header files for external libraries in my source code?

I am trying to extract archived files in my project using Libarchive.
On a standalone code, i include libarchive's archive.h using:
#include <archive.h>
But I have seen on projects that header files are not included directly, they use:
#include <poppler/cpp/poppler-document.h>
Why is poppler-document.h not directly included?
So how are these directories specified?
If you're on visual studio you can go on Project Properties/"C/C++"/General and look at the additional include directories where you can add the directory of where those includes are. For including the .libs themselves you'll need to go in Linker/Additional Library Directories

cannot open the header file in C++

I'm doing my assignment that need to using the #include function
but I found that after I define the header file, I cannot open the header file in the main.cpp
and I also didn't find any xxx.h file in the project file
here is the situation
The reason of search.h can open is I found that in external dependencies file, there is a search.h, but the search.h I want to open is not the search.h in external dependencies file
You don't have header files in your project. Create the header files xxx.h in the project directory. So the compiler will be able to locate them.
If the person who gave you the project has provided you the header files along with the project requirements then, just copy and paste the xxx.h files into the project directory. This would solve your problem.
To learn more about the header file. Click on the below tutorial link
Header Files
How to add header files in Visual Studio 2010 - Youtube
It looks like you don't have any header files included in your project. Visual Studio is attempting to find the header files in the header directory of your project but it cannot find any. Save your header files into separate files and add them to your header directory in the project. Then you should not have any problem.

Storing a C++ header file globally in Windows

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>

C++ Including Visual Studio header files in Qt project. <xstring> include error

I have found a library to generate barcodes (libbarpp). I would like to use this library in my Qt project.
Doing a svn checkout of the source: http://libbarpp.googlecode.com/svn/trunk/ reveals a nice VS example in the src folder. I opened the project in VS and found the included header files. I have included these header files in my Qt project, however i encountered a problem when several of the files required a system header file
#include <xstring>
In VS i can see the this file is located in (on my system):
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring
However the files does not have any extension and i don't really know what to do with it.
Do i need to include something in my Qt project file in order to use this VS file?
I tried including
CONFIG += stl
to my Qt project file, but with no luck.
Any help or comments is greatly appreciated.
EDIT: I'm using Qt 5.2.1 with MinGW compiler
xstring is a Microsoft specific header that contains implementation of std::basic_string and some related specializations.
It shouldn't be included directly in the first place and unless the code you are talking about is using something implementation specific from that file you should be fine replacing it with just:
#include <string>

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>