C++ cannot open source file, additional directory listed - c++

I am using Visual Studio 2019, and I'm trying to include codes from open source GLFW. Things were working completely fine, but when I tried to make another project based on this method again it's not working.
It shows 'Cannot open include file: 'GLFW/glfw3.h': No such file or directory'

I reproduced the steps to add GLFW and it worked well. You could check whether there are any missing steps.
Create a Dependencies folder in your project directory, copy the include and lib-vc2019 folders of glfw-3.3.2.bin.WIN32 to Dependencies.
Set Configuration to All Configurations and set Platform to Win32
Add $(SolutionDir)Dependencies\GLFW\include in Proeperties->C/C++->General->Additional Include Directories
Add $(SolutionDir)Dependencies\GLFW\lib-vc2019 in Proeperties->Linker->General->Additional Library Directories
Add glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;%(AdditionalDependencies) in Proeperties->Linker->Input->Additional Dependencies

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

Boost C++ Libaries in Visual Studio 2017 C++ Project - "Cannot open include file"

I'm trying to add the Boost C++ Libraries to my C++ project created with Visual Studio 2017.
I have followed the instructions here.
When that didn't work I tried the advice in this post. Neither solutions worked for me.
What I have done:
Downloaded boost_1_69_0-msvc-14.1-64.exe from this precompiled boost libraries page
Installed to D:\local\boost_1_69_0
In my project I added D:\local\boost_1_69_0 to Properties > VC++ Directories > Include Directories and added D:\local\boost_1_69_0\lib64-msvc-14.1 to Properties > VC++ Directories > Library Directories
I have my project set to x64 and the above settings were set in the x64 configuration
When I try to build my project I get this error:
Error C1083 Cannot open include file: 'boost/regex.hpp': No such file or directory
Which points to this line of code in one of my .cpp files:
#include <boost/regex.hpp>
Please go to D:\local\boost_1_69_0 folder and see if you have a sub-folder named include in there. If you do, then instead of D:\local\boost_1_69_0 you need to set D:\local\boost_1_69_0\include in Properties > VC++ Directories > Include Directories
In other words, try to find the file you are including on your hard drive. Look at the full path to the file. Compare that full path with the path you added to the list of include directories (Properties > VC++ Directories > Include Directories) concatenated with the relative path you provided just before the filename in your include directive (boost). See if the two are the same.
If that does not help, then make sure you changed list of include directories for the same build configuration as you are attempting to build (if you build Debug, make sure you changed configuration for Debug too). Since VS 2015 IDE stopped making sure the two are selected in sync, which is annoying.
If your files are copied, then you have to compile the regular library.... If the same version of the compiler copies the machine.
Found out it was failing because I had included the same .cpp file which has the boost include into my unit test project which did NOT have the Include/Library folders set. The settings in my original question work now.

Additional Include Directories not working

In Visual Studio C++, I go to the project settings, additional include directories, then add the directory of the file to the list. However, when I try to include the file, it can't find it, I've restarted Visual Studio and that doesn't work.
Here's my include directories:
A picture of my include directories
Here's the error I get:
A picture of the Error
The problem was that I was modifying the include directories under the release configuration mode
Make sure to switch to debug before modifying it.
Here is a way to add your file to the Project:
Go left click on the project and choose "Add"->"ExistingItem"
A simple file browser will open, now you can just pick the desired file and confirm.
Now you need just to #include "TheNewFile where you need the new file...

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 2008 Qt Project configuration

I am trying to configure my dll project so that I can access QtCore4.dll and QtGui4.dll functions.
In my project properties under c/c++, Additional Include Directories I have added ...\Qt\4.6.0;
project properties under Linker Additional library directories I have added Qt\4.6.0\lib
Right, so what #include do I need to put in my header files so that I can get the functionality?
Before I was using dependencies and using the includes and but now I have removed the dependencies I am getting a 'cannot open file: 'QtCore/qcoreapplication.h': no such file or directory error.
This project is making me feel like a moron.
Thanks.
Your additional Include directory should be ..\qt\4.6.0\include. If you use qmake or the VS plugin all this is done automatically.
Save yourself time and hassle, get the plugin: http://qt.nokia.com/downloads