Unable to include header file in C++ console application project - c++

I have been trying linking of a .lib file and also including a header file in my C++ console application project. I copied the C++ header file from one of my other projects, and pasted it under Header Files folder in console application project. Here's the screenshot to see: http://i.imgur.com/JFFIn.png
However, when I try to include the header in my code as #include..., I do not get an intellisense with my header file's name. (I only see targetver.h, stdafx.h and Debug folder)
I tried to point Add additional include directories in my C++ console application project properties to the Project folder itself, but that doesn't seem to help and the file still doesn't show up.
If I write the name of the header file as #include "DllTest.h", I get an error saying: Cannot open include file: 'DLLTest.h': No such file or directory c:\users\ht\documents\visual studio 2010\projects\dlltest\dlltestconsole\dlltestconsole.cpp
How is the header file included in here, so that it starts appearing? If I add a new item > Header File, name it to DLLTest.h and copy paste the header files content here, it just shows up normally. How will the header file which is copied - pasted into Header Files folder show up in the code?

In C++ projects, the things that look like folders in the Solution Explorer aren't actually folders, they are filters. They are UI-only entities that can be used to organize project items in the IDE. They do not in any way reflect the structure or location of items on disk, though. You can add a file from any location on disk to any filter in the solution.
The compiler knows nothing of these filters; it only knows about files as they exist on disk.
In your case, the files are not located in your project folder. You'll either need to:
copy your files into your project folder, then add them to the project from there (right-click on the solution then Add Existing Item), or
add the files from where they are, then add their location to the "Additional Include Directories" property in the project properties.
I do not know of any way to have the IDE automatically move files to the project directory when you copy and paste them into the project. The C++ project system is fundamentally different from the project system used for C# and VB.

Related

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

Include c++ files outside project directory in Eclipse

I have a problem regarding including files that are outside project directory (c). So I have a project in a workspace. There is a folder somewhere on my hard drive, containing a pair of .h and .c files. I would like to use them in several projects, that's why I wanted to place it outside the project.
I tried including this folder, .h file actually in many ways, but the compiler doesn't seem to see the content of it. I can successfully include the file, but the functions inside are not visible.
In the properties of the project -> C/C++ General -> Paths and symbols I have added the folder. What else should I do?
Add the relative path of all those *.c and *.h file.
#include "path_to_header/lib1.h"
#include "path_to_file/file1.c"
I was wondering about the same recently, here is what worked for me:
You have to mark the files as source code. Open project properties dialog and go to source location tab
then you can use Link Folder to select absolute path or you can use the variables to keep it relative to project file or workspace.
For other configurations Add folder was enough since they were already linked.
You also need to add include paths to c or c++ here
There probably already are some default paths so just add the new ones.
It can also be relative using variables.
I had more sub folders so I added them individually and did not use and relative path in #include at all.

Can you use a .exe project as a library in another project in the same solution?

As title says. I'm adding a project to an existing open source solution and would like to use some of the functionality of its .exe tools in my project. I added it as a reference and added its directory to additional includes but I cant seem to include its header file.

Visual C++ project can't find 'xyz.h' file for external dependencies

I have a Visual Studio C+++ project, and in the project I have some header files I want to get via the include directories setting on the project properties.
As far as I know that's all set up correctly. I've added the folder path which contains the files and the 3 files appear in the external dependencies folder under my project in Visual Studio.
The problem is that:
when I write the include "xyz.h" for one of the three files, I get "can not find file blah blah" error. This only occurs for one of the three. The other two work fine and I can include them just fine. They are all just basic headers.
Does anyone have any idea why one of my files would fail to work. Thanks
When you setting up the project properties such ad additional include directories, make sure to select "All configurations" in the project properties window. look at the image.
Sorry, the problem was that the file was being used by some background process, so the dll that I was trying to load couldn't open the file.

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.