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

小结

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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值