简体   繁体   English

无法打开源文件; C++; 视觉工作室

[英]Cannot open source file; C++; Visual Studio

I'm learning about dll files and trying to create one.我正在了解 dll 个文件并尝试创建一个。 My problem is that when i try to build my solution in visual studio, i'm getting errors saying eg "cannot open source file string.h".我的问题是,当我尝试在 visual studio 中构建我的解决方案时,我收到错误消息,例如“无法打开源文件 string.h”。

This happens for multiple header files.多个 header 文件会发生这种情况。 The error is produced by a file other than mine, which includes string.h该错误是由我以外的文件产生的,其中包括 string.h

error list from VS来自 VS 的错误列表

I can't figure out how to fix this error, and any help will be greatly appreciated!我不知道如何解决这个错误,任何帮助将不胜感激!

Visual Studio C++ 包含目录的图像

Double clicking item will give you option to change the list.双击项目将为您提供更改列表的选项。 But by default it is generally not required.但默认情况下,通常不需要。 Until it is changed.直到它被改变。 If you feel that you have messed everything.如果你觉得你把一切都搞砸了。 Just uninstall visual studio and reinstall it.只需卸载 Visual Studio 并重新安装即可。 Every thing will be back to normal.一切都会恢复正常。

I bet you've resolved it by now, but for others who experience this issue, unless you directly deleted files from installed visual studio directory I wouldn't resort to an uninstall/reinstall solution, because then you don't know what went wrong and why.我敢打赌您现在已经解决了它,但是对于遇到此问题的其他人,除非您直接从已安装的 Visual Studio 目录中删除文件,否则我不会求助于卸载/重新安装解决方案,因为那样您就不知道出了什么问题为什么。

When I ran into this issue.当我遇到这个问题时。 Two things I had to check and fix to resolve我必须检查并修复两件事才能解决

  1. XML file may have been directly edited, and butchered XML 文件可能已被直接编辑和屠宰
    • Edit .vcxproj file, make sure that paths between IncludePath , and LibraryPath tags aren't separated by new lines (cr/lf)编辑 .vcxproj 文件,确保IncludePathLibraryPath标签之间的路径没有被新行分隔 (cr/lf)
  2. Project properties may no longer be including default directories.项目属性可能不再包含默认目录。
    • Right click project properties.右键单击项目属性。 Navigate to VC++ Directories, and select "inherit from parent or project defaults" for: Executable Directories, Reference Directories, Library WinRT Directories, Source Directories, Exclude Directories.导航到 VC++ 目录,然后选择“从父​​级或项目默认值继承”:可执行目录、参考目录、库 WinRT 目录、源目录、排除目录。

I had the same problem with a Visual Studio Project i downloaded from github .我从github下载的 Visual Studio 项目遇到了同样的问题。

Issue was the Windows SDK Version was set to a version i hadn't installed .问题是Windows SDK 版本设置为我未安装的版本。 I solved it by changing the Configuration Properties -> General -> Windows SDK Version to "< inherit from parent or project defaults >"我通过将 Configuration Properties -> General -> Windows SDK Version 更改为“< inherit from parent or project defaults >”来解决它

在此处输入图像描述

Hmph 尝试卸载并重新安装 Visual Studio 这件事发生在我 2 年前的 Vs 2017 上,因为我打开了一个损坏的源并且它损坏了我的 Visual Studio :(

I had this issue once.我曾经遇到过这个问题。 The reason was: in VC++ Directories > Include Directories option I had ";"原因是:在 VC++ 目录 > 包含目录选项中我有“;” at the end of the line.在行尾。 I edited that property and left a symbol there.我编辑了那个属性并在那里留下了一个符号。 It should end with "$(IncludePath)".它应该以“$(IncludePath)”结尾。 After removing that character I managed to get it working.删除那个角色后,我设法让它工作。

Instead of reinstalling Visual Studio review your project settings.而不是重新安装 Visual Studio 检查您的项目设置。

Cleaning and rebuilding project may help, as well as closing and reloading project.清理和重建项目可能会有所帮助,以及关闭和重新加载项目。 You may also try removing binary build artifacts generated for your project, such as .lib and .obj您还可以尝试删除为您的项目生成的二进制构建工件,例如 .lib 和 .obj

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

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