学堂 学堂 学堂公众号手机端

Visual Studio 2017工程在Visual Studio 2019打开碰到的问题

lewis 1年前 (2024-03-31) 阅读数 4 #技术


文章目录​​小结​​​​Error code: 0x80004005​​​​cannot open source file "xxx.h"​​​​参考​​小结

Visual Studio 2017的工程可以正常使用,在Visual Studio 2019中打开碰到两个问题,Error code: 0x80004005 和 cannot open source file “xxx.h” ,解决了这两个问题。

Error code: 0x80004005

参考​​Visual Studio 2017: Project is out of date with error (0x80004005)​​


假定是​​HelloWorld​​​的工程,那么修改​​HelloWorld.vcxproj​​​文件,将以下内容:
​​​<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">​​​ 修改为:
​<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">​​ 修改后,Visual Studio 2019的​​HelloWorld​​工程提示:​​The project 'HelloWorld' has been modified outside the environment, Press Reload to ...​

这里进行Reload后,这个​​error (0x80004005)​​就解决了。

cannot open source file “xxx.h”

以上​​error (0x80004005)​​​问题解决后,会有新问题​​cannot open source file "xxx.h"​​​出现。
可能 是Visual Studio 2017和Visual Studio 2019在查找路径的方法不一样。我发现可能的具体原因应该是文件查找方法不知怎么地由工程目录改成了文件所在目录,所以需要修改相对路径。即使在工程属性里添加目录也不行:也就是在
工程属性–>VC++ Directories --> Include Directories添加绝对路径​​​C:\Development\Hello_World\HelloWorld\ros_lib​​也不能全部解决问题。

这里需要在源文件中修改:
例如在​​​duration.cpp​​​这个源文件中由工程目录:
​​​#include "ros/duration.h"​​​ 修改为:
​#include "ros_lib/ros/duration.h"​​ 这里在​​duration.cpp​​这个源文件的所在目录有一个​​ros_lib​​的目录,下面再有​​ros/duration.h​​,添加​​ros_lib​​在前面后就可以找到这个​​duration.h"​​头文件了。

另外把尖括号修改成引号,例如:
把​​​#include <geometry_msgs/Twist.h>​​​ 修改为:
​#include "../ros_lib/geometry_msgs/Twist.h"​

最后,如果直接在Visual Studio 2019中直接创建新的工程好像也没有这么多奇奇怪怪的问题。

参考

​​Visual Studio 2017: Project is out of date with error (0x80004005)​​​​c++ cannot ​​

​​open source file ‘SOLVED’​​​​Stack Overflow: C++ cannot open source file​​

版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门