Myath
Myath

Reputation: 563

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.

Upvotes: 0

Views: 1285

Answers (1)

Myath
Myath

Reputation: 563

All previous No such file or directory errors were the result of some combination of:

  1. Mismatching project properties Configuration and Platform
  2. Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.

The solution to the problem consists of the following:

  1. Under project Properties > C/C++, add the path to the include to Additional Include Directories.
  2. 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.
  3. Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

Upvotes: 1

Related Questions