【问题标题】:VisualStudio C++ created executable not deployable on other Win10 computers (error "0xc000007b")Visual Studio C++ 创建无法在其他 Win10 计算机上部署的可执行文件(错误“0xc000007b”)
【发布时间】:2020-01-27 09:43:54
【问题描述】:

当我使用 VisualStudio(2017 社区版)编译一个简单的“Hello World”C++ 程序时,可执行文件在装有 Windows 10 的开发计算机上运行,​​但在具有相同操作系统和架构的另一台计算机上,程序无法启动出现错误“0xc000007b”(“应用程序无法正确启动”)。

是否有人建议我可以尝试使用 VisualStudio 创建可移植的可执行文件?这似乎是 VisualStudio 的一个常见问题,但我在网上没有找到任何有用的东西来解决它。

这是我的程序的 C++ 代码:

#include <Windows.h>

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow)
{
    MessageBox(NULL, "Program started", "Message", MB_OK);
    return 0;
}

这是根据 VisualStudio 使用的一组编译选项(x64Release 模式):

/GS /TP /W3 /Zc:wchar_t /I"D:\test\build" /I"D:\test"
/I"C:\Program Files (x86)\Visual Leak Detector\include" /Gm- /O2 /Ob2
/Fd"test1.dir\Release\vc141.pdb" /Zc:inline /fp:fast /D "_WINDOWS"
/D "_VARIADIC_MAX=10" /D "NOMINMAX" /D "NDEBUG" /D "CMAKE_INTDIR=\"Release\""
/D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /Oy /MD /Fa"Release/"
/EHsc /nologo /Fo"test1.dir\Release\" /Ot /Fp"test1.dir\Release\test1.pch" /diagnostics:classic

这是dumpbin报告的链接到可执行文件的库列表:

D:\test\build\Release>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\dumpbin.exe" /DEPENDENTS test1.exe
Microsoft (R) COFF/PE Dumper Version 14.16.27032.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file test1.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    USER32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    KERNEL32.dll

  Summary

        1000 .data
        1000 .pdata
        1000 .rdata
        1000 .reloc
        1000 .rsrc
        1000 .text

【问题讨论】:

    标签: windows visual-c++


    【解决方案1】:

    您需要在目标计算机上安装相应的 Visual C++ Redistributable

    Redistributable for Visual C++ 2015, 2017, 2019

    在您的开发计算机上已经安装了 Visual Studio。

    【讨论】:

    • 我没有提到它,但我已经将VCRUNTIME140.dll与可执行文件打包在一起。问题不是缺少 DLL,而是操作系统无法加载可执行文件。此外,必须有一种方法可以为 VC 创建的二进制文件创建安装程序,而不需要用户在目标计算机上单独安装 VC-Runtimes。
    • 某些 DLL 库可能仅在运行时加载。在调试时,您可以在 Visual Studio 的“模块”窗口中看到这一点。或者您使用DependencyWalker (x64) 和“个人资料”。当目标计算机上不可用时(例如 here with WiX toolset ),大多数安装程序都提供了安装可再发行组件的可能性
    • 刚刚有机会在目标计算机上测试它,安装“可再发行”包确实解决了这个问题。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    相关资源
    最近更新 更多