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)
就解决了。
以上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
版权声明
本文仅代表作者观点,不代表博信信息网立场。