mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file … Access is denied

后端 未结 11 1480
礼貌的吻别
礼貌的吻别 2021-02-02 07:02

I often have this problem even when I build a new C++ project and try to build a release file.

I use Visual studio 2008. One thing that may cause this problem is my code

11条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 07:53

    I worked around this with a "wrapper" program for mt.exe, one that reran it until it succeeded. Save the following code as mt-wrapper.cpp:

    #include 
    #include 
    #include 
    
    // Build from a Visual Studio Command Prompt with "cl /O2 /Gy /Femt.exe mt-wrapper.cpp"
    
    int __cdecl wmain(int argc, WCHAR **argv, WCHAR **env)
    {
        // Stop outputting text.
        fclose(stdout);
        fclose(stderr);
    
        // Run the original mt.exe, which has been renamed to mt-orig.exe .
        for (;;)
        {
            // Try to run the original mt.
            intptr_t iStatus = _wspawnve(_P_WAIT, L"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\mt-orig.exe", argv + 1, env);
            if (iStatus == 0)
                break;
    
            // Try again, after a short wait.
            ::Sleep(100);
        }
    
        return 0;
    }
    

    Build this program, go to your C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin folder, rename the old mt.exe to mt-orig.exe (and the mt.exe.config to mt-orig.exe.config), and put this wrapper program in there as mt.exe. Now, when you build, it will retry running the original mt.exe until it succeeds.

    Oddly, MSBuild doesn't seem to check for a zero status when deciding that mt.exe has succeeded — it seems to look for error messages written to stdout/stderr. So this program closes both of those before spawning the original mt.exe. Anyone feeling industrious can apply the advice found here to save the output of the successful run of the original mt.exe, and output it to stdout/stderr.

提交回复
热议问题