Visual Studio在哪里查找c++头文件?

时间:2023-01-18 00:07:26

I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.

我从SourceForge (HoboCopy,如果您感兴趣的话)上查找了一个c++应用程序的副本,并尝试编译它。

Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?

Visual Studio告诉我它找不到一个特定的头文件。我在源代码树中找到了这个文件,但是我需要把它放在哪里,以便编译时可以找到它?

Are there special directories?

有特殊的目录吗?

5 个解决方案

#1


90  

Visual Studio looks for headers in this order:

Visual Studio按照以下顺序查找标题:

  • In the current source directory.
  • 在当前源目录中。
  • In the Additional Include Directories in the project properties (under C++ | General).
  • 在附加的包含项目属性的目录(在c++ |通用)。
  • In the Visual Studio C++ Include directories under ToolsOptionsProjects and SolutionsVC++ Directories.
  • Visual Studio c++中包括目录下工具→选项→→vc++目录项目和解决方案。

In your case, add the directory that the header is in to the project properties.

在您的示例中,将标题所在的目录添加到项目属性中。

#2


10  

If the project came with a Visual Studio project file, then that should already be configured to find the headers for you. If not, you'll have to add the include file directory to the project settings by right-clicking the project and selecting Properties, clicking on "C/C++", and adding the directory containing the include files to the "Additional Include Directories" edit box.

如果项目附带了一个Visual Studio项目文件,那么应该已经将其配置为为为您查找标题。如果没有,您必须通过右键单击项目并选择Properties、单击“C/C++”并将包含include文件的目录添加到“附加包含目录”编辑框,将包含include文件的目录添加到项目设置中。

#3


6  

Tried to add this as a comment to Rob Prouse's posting, but the lack of formatting made it unintelligible.

试图把这句话添加到Rob Prouse的贴子中作为一个评论,但是由于缺少格式的限制,这句话很难理解。

In Visual Studio 2010, the "Tools | Options | Projects and Solutions | VC++ Directories" dialog reports that "VC++ Directories editing in Tools > Options has been deprecated", proposing that you use the rather counter-intuitive Property Manager.

在Visual Studio 2010中,“工具|选项|项目和解决方案| vc++目录”对话框报告“工具>选项中的vc++目录编辑已被弃用”,建议您使用相当反直觉的属性管理器。

If you really, really want to update the default $(IncludePath), you have to hack the appropriate entry in one of the XML files:

如果您真的非常想要更新默认的$(IncludePath),您必须在其中一个XML文件中修改适当的条目:

\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props

\程序文件(x86)\[\ Microsoft.Cpp \ v4.0 \ \ Win32 \ PlatformToolsets \ v100 \ Microsoft.Cpp.Win32.v100.props平台

or

\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\PlatformToolsets\v100\Microsoft.Cpp.X64.v100.props

\程序文件(x86)\[\ Microsoft.Cpp \ v4.0 \ \ x64 \ PlatformToolsets \ v100 \ Microsoft.Cpp.X64.v100.props平台

(Probably not Microsoft-recommended.)

(可能不是Microsoft-recommended。)

#4


4  

There seems to be a bug in Visual Studio 2015 community. For a 64-bit project, the include folder isn't found unless it's in the win32 bit configuration Additional Include Folders list.

Visual Studio 2015社区似乎有一个bug。对于64位项目,除非在win32位配置附加包含文件夹列表中,否则不会找到include文件夹。

#5


1  

There exists a newer question what is hitting the problem better asking How do include paths work in Visual Studio?

有一个新的问题,什么更好地解决了这个问题,那就是如何在Visual Studio中包含路径?

There is getting revealed the way to do it in the newer versions of VisualStudio

在VisualStudio的新版本中,我们已经找到了实现它的方法。

  • in the current project only (as the question is set here too) as well as
  • 在当前的项目中(正如这里所设置的问题一样)
  • for every new project as default
  • 默认为每个新项目

The second is the what the answer of Steve Wilkinson above explains, what is, as he supposed himself, not the what Microsoft would recommend.

第二个问题是史蒂夫•威尔金森(Steve Wilkinson)的回答解释了什么,正如他自己所认为的,不是微软会推荐的。

To say it the shortway here: do it, but do it in the User-Directory at

在这里用shortway表示:做它,但在用户目录at中做它

C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0

C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0

in the XML-file

在xml文件中

Microsoft.Cpp.Win32.user.props

Microsoft.Cpp.Win32.user.props

and/or

和/或

Microsoft.Cpp.x64.user.props

Microsoft.Cpp.x64.user.props

and not in the C:\program files - directory, where the unmodified Factory-File of Microsoft is expected to reside.

而不是在C:\程序文件-目录中,微软的未修改的工厂文件预计将驻留在那里。

Then you do it the way as VisualStudio is doing it too and everything is regular.

然后你就像VisualStudio一样做,一切都很正常。

For more info why to do it alike, see my answer there.

更多的信息为什么做一样,看我的答案在那里。

#1


90  

Visual Studio looks for headers in this order:

Visual Studio按照以下顺序查找标题:

  • In the current source directory.
  • 在当前源目录中。
  • In the Additional Include Directories in the project properties (under C++ | General).
  • 在附加的包含项目属性的目录(在c++ |通用)。
  • In the Visual Studio C++ Include directories under ToolsOptionsProjects and SolutionsVC++ Directories.
  • Visual Studio c++中包括目录下工具→选项→→vc++目录项目和解决方案。

In your case, add the directory that the header is in to the project properties.

在您的示例中,将标题所在的目录添加到项目属性中。

#2


10  

If the project came with a Visual Studio project file, then that should already be configured to find the headers for you. If not, you'll have to add the include file directory to the project settings by right-clicking the project and selecting Properties, clicking on "C/C++", and adding the directory containing the include files to the "Additional Include Directories" edit box.

如果项目附带了一个Visual Studio项目文件,那么应该已经将其配置为为为您查找标题。如果没有,您必须通过右键单击项目并选择Properties、单击“C/C++”并将包含include文件的目录添加到“附加包含目录”编辑框,将包含include文件的目录添加到项目设置中。

#3


6  

Tried to add this as a comment to Rob Prouse's posting, but the lack of formatting made it unintelligible.

试图把这句话添加到Rob Prouse的贴子中作为一个评论,但是由于缺少格式的限制,这句话很难理解。

In Visual Studio 2010, the "Tools | Options | Projects and Solutions | VC++ Directories" dialog reports that "VC++ Directories editing in Tools > Options has been deprecated", proposing that you use the rather counter-intuitive Property Manager.

在Visual Studio 2010中,“工具|选项|项目和解决方案| vc++目录”对话框报告“工具>选项中的vc++目录编辑已被弃用”,建议您使用相当反直觉的属性管理器。

If you really, really want to update the default $(IncludePath), you have to hack the appropriate entry in one of the XML files:

如果您真的非常想要更新默认的$(IncludePath),您必须在其中一个XML文件中修改适当的条目:

\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props

\程序文件(x86)\[\ Microsoft.Cpp \ v4.0 \ \ Win32 \ PlatformToolsets \ v100 \ Microsoft.Cpp.Win32.v100.props平台

or

\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\PlatformToolsets\v100\Microsoft.Cpp.X64.v100.props

\程序文件(x86)\[\ Microsoft.Cpp \ v4.0 \ \ x64 \ PlatformToolsets \ v100 \ Microsoft.Cpp.X64.v100.props平台

(Probably not Microsoft-recommended.)

(可能不是Microsoft-recommended。)

#4


4  

There seems to be a bug in Visual Studio 2015 community. For a 64-bit project, the include folder isn't found unless it's in the win32 bit configuration Additional Include Folders list.

Visual Studio 2015社区似乎有一个bug。对于64位项目,除非在win32位配置附加包含文件夹列表中,否则不会找到include文件夹。

#5


1  

There exists a newer question what is hitting the problem better asking How do include paths work in Visual Studio?

有一个新的问题,什么更好地解决了这个问题,那就是如何在Visual Studio中包含路径?

There is getting revealed the way to do it in the newer versions of VisualStudio

在VisualStudio的新版本中,我们已经找到了实现它的方法。

  • in the current project only (as the question is set here too) as well as
  • 在当前的项目中(正如这里所设置的问题一样)
  • for every new project as default
  • 默认为每个新项目

The second is the what the answer of Steve Wilkinson above explains, what is, as he supposed himself, not the what Microsoft would recommend.

第二个问题是史蒂夫•威尔金森(Steve Wilkinson)的回答解释了什么,正如他自己所认为的,不是微软会推荐的。

To say it the shortway here: do it, but do it in the User-Directory at

在这里用shortway表示:做它,但在用户目录at中做它

C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0

C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0

in the XML-file

在xml文件中

Microsoft.Cpp.Win32.user.props

Microsoft.Cpp.Win32.user.props

and/or

和/或

Microsoft.Cpp.x64.user.props

Microsoft.Cpp.x64.user.props

and not in the C:\program files - directory, where the unmodified Factory-File of Microsoft is expected to reside.

而不是在C:\程序文件-目录中,微软的未修改的工厂文件预计将驻留在那里。

Then you do it the way as VisualStudio is doing it too and everything is regular.

然后你就像VisualStudio一样做,一切都很正常。

For more info why to do it alike, see my answer there.

更多的信息为什么做一样,看我的答案在那里。