我们正在将 Visual C++ 项目切换到 vc141 工具链 (VS 2017)。我们遇到了 Visual Studio 无法使用 .pdb
的问题来源.obj
的文件文件不再存在(例如,因为它们已在构建服务器上编译)。
让我们来看一个非常简单的可执行项目:
#include <iostream>
int main() {
std::cout << "Hello world\n";
std::cin.ignore();
}
.vcxproj
文件都是默认的,除了<GenerateDebugInformation>true</GenerateDebugInformation>
生成 pdb 文件。
复现步骤,始终使用VS2017:
- 编译项目
- 在
main
内放置一个断点 - 去除中间体
Debug/
包含.obj
的目录文件 - 通过配置管理器禁用运行时构建(因此它不会重新创建它们)
- 开始调试 session
这适用于 vc100 (VS 2010) 工具链,并且断点有效,但它会立即触发 vc141 的以下错误:
Error: Unable to open file
<path>\Debug\main.obj. Error code = 0x80070003.
这个非常通用的错误代码确实对应于 FACILITY_WIN32/ERROR_PATH_NOT_FOUND
. main.obj
的路径可以在 .pdb
的两个版本中找到文件,因此我们不清楚为什么 VS 在找不到它时突然崩溃。
“模块” View 显示 .pdb
文件似乎已正确加载。此外,断点的工具提示显示以下错误:
The breakpoint will not currently be hit. Unexpected symbol reader error while processing MyUser_141.exe.
考虑到我们无法在实际应用程序中编译二进制文件的机器上进行调试,对于这个问题有什么解决方案或变通方法?
这是完整的 .vcxproj
文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<RootNamespace>MyUser_141</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<ProjectGuid>{90982029-29B8-4C9B-AFB7-B8F555F15C1E}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
进一步研究:
我们尝试了其他一些工具链版本。该错误在 v14.0 (VS 2015) 中不存在,但在 14.11 (VS2017 15.3) 中存在。
使用
v141_xp
,据我们所知,它使用相同的工具链,但系统库较旧,有效。
最佳答案
要解决此问题,请在构建可执行文件和 DLL 的项目的属性页中进行以下更改:
配置属性 -> 链接器 -> 调试 -> 生成调试信息 -> 生成针对共享和发布优化的调试信息
没有链接步骤的静态库不需要这个。 .EXE 和 DLL 可以。
关于c++ - 使用 pdb 文件调试时 VS2017 阻塞在不存在的目标文件上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50489343/