简体   繁体   English

Visual Studio C++ 如何在前缀文件夹中添加 header 文件

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

I cloned a github C++ repository.我克隆了一个 github C++ 存储库。 The repository is not a VS project.存储库不是 VS 项目。 So I manually created a VS C++ blank project and added the files from the repo to the project.所以我手动创建了一个 VS C++ 空白项目,并将 repo 中的文件添加到项目中。 The files are not copied.文件不会被复制。 This is not the problem.这不是问题。

The repo directory looks like this: repo 目录如下所示:

include\NTL\*.h
src\*.cpp

*.h means a bunch of header files and *.cpp means a bunch of .cpp source files. *.h表示一堆 header 文件, *.cpp表示一堆.cpp源文件。

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 ).问题是.cpp文件有#include <NTL/*.h>并且当我构建时,VS 无法找到 header 文件( No such file or directory )。 Adding the path to the include to the Include Directories in project properties didn't help.将包含的路径添加到项目属性中的include目录没有帮助。

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. 编辑:经过一些实验,我发现该错误与 #include <NTL/*.h>中的前缀 NTL无关,而是与文件是否复制到项目目录中有关。 Even though the files appear in VS project view, they must be copied into the project directory. 即使文件出现在 VS 项目视图中,也必须将它们复制到项目目录中。

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. 编辑:我设法编译项目的唯一方法是将包含 header 文件的整个 NTL目录放在项目目录中。 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:所有以前的No such file or directory错误都是以下某些组合的结果:

  1. Mismatching project properties Configuration and Platform项目属性配置和平台不匹配
  2. Some .h files were actually missing from NTL github repo, eg mach_desc.h . NTL github repo 中实际上缺少一些.h文件,例如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 .在项目Properties > C/C++下,将包含的路径includeAdditional Include Directories
  2. VS project has a separate set of properties for each combination of Configuration and Platform. VS 项目对于配置和平台的每个组合都有一组单独的属性。 Make sure that step 1 applies to the active Configuration and Platform.确保步骤 1 适用于活动配置和平台。 Eg 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.例如,如果项目当前配置为为 Debug x64 构建(活动配置:Debug 和 Platform:x64),请确保第 1 步适用于 Debug x64,而不是像 Release Win32 或 Release x64 等。
  3. Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM