Skip to content

MSVC /Fo parameter not handled correctly #1844

Closed

Description

@mpoeter

According to the MSVC documentation /Fo "Specifies an object (.obj) file name or directory to be used instead of the default."

And further:

To use the /Fo option to set an output directory for all object files created by the CL command, specify the directory as the pathname argument. A directory is indicated by a trailing slash or backslash in the pathname argument. Use an escaped backslash (a double backslash), if you're using a quoted path. The directory path can be absolute, or relative to the source directory. The specified directory must exist, or the compiler reports error D8003. The directory isn't created automatically.

At the moment sccache always treats /Fo as a filename. Unfortunately by default Visual Studio sets this to $(IntDir) ("Path to the directory specified for intermediate files."). So as a result instead of a main.obj I get a Release.obj.

MSBuild.exe .\CppTest.sln /t:Build /p:Configuration=Release "/verbosity:normal" "/p:CLToolExe=cl.exe" "/p:CLToolPath=C:\dev\sccache"
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 7/25/2023 2:04:36 PM.
Project "C:\dev\CppTest\CppTest.sln" on node 1 (Build target(s)).
ValidateSolutionConfiguration:
  Building solution configuration "Release|x64".
Project "C:\dev\CppTest\CppTest.sln" (1) is building "C:\dev\CppTest\CppTest.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
  Creating directory "x64\Release\".
  Creating directory "x64\Release\CppTest.tlog\".
InitializeBuildStatus:
  Creating "x64\Release\CppTest.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  C:\dev\sccache\cl.exe /c /Z7 /nologo /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t / 
  Zc:forScope /Zc:inline /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:queue main.cpp
  main.cpp
Link:
  C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\dev\CppTest\x64\Release\CppTest.ex 
  e" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:" 
  level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\dev\CppTest\x64\Release\CppTest.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /LTCGOUT:"x64\Re 
  lease\CppTest.iobj" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\dev\CppTest\x64\Release\CppTest.lib" /MACHINE:X64 x64\Release\main.obj
LINK : fatal error LNK1181: cannot open input file 'x64\Release\main.obj' [C:\dev\CppTest\CppTest.vcxproj]
Done Building Project "C:\dev\CppTest\CppTest.vcxproj" (default targets) -- FAILED.

Done Building Project "C:\dev\CppTest\CppTest.sln" (Build target(s)) -- FAILED.


Build FAILED.

"C:\dev\CppTest\CppTest.sln" (Build target) (1) ->
"C:\dev\CppTest\CppTest.vcxproj" (default target) (2) ->
(Link target) ->
  LINK : fatal error LNK1181: cannot open input file 'x64\Release\main.obj' [C:\dev\CppTest\CppTest.vcxproj]

    0 Warning(s)
    1 Error(s)


ls C:\dev\CppTest\x64

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         7/25/2023   2:04 PM                Release
-a----         7/25/2023   2:04 PM           3530 Release.obj

I am curious how you use sccache on Windows at the moment that this is not an issue for you. For me it looks like this is the last missing piece to actually get this to work.

Activity

  1. AudranDoublet commented on Jul 25, 2023

    @AudranDoublet
    Contributor

    Duplicate of #1687 I guess. But I also encountered that issue and proposed this fix: #1836
    You may be able to use it (before it's merged) by building sccache

  2. mpoeter commented on Jul 26, 2023

    @mpoeter
    Author

    Thank you @AudranDoublet! I have searched a lot yesterday, but for some reason I neither found that issue, nor your PR. 🤷‍♂️

    I will definitely give your PR a try!

  3. assarbad commented on Sep 11, 2023

    @assarbad

    I am curious how you use sccache on Windows at the moment that this is not an issue for you. For me it looks like this is the last missing piece to actually get this to work.

    This comment may be of interest:

    one addition I can make to the short props file sample above is this line:
    <UseMultiToolTask>true</UseMultiToolTask>

    With that VS/MSBuild should compile one file at a time and hopefully it will be faster due to parallelism. Another thing it can help is that it is easier to cancel builds.

    I think what this effectively does is suppress MSBuild Batching which yields the "one file at a time" behavior described.

    That needs to go into a <PropertyGroup />, of course, which itself should be part of the project or get imported directly or transiently (e.g. Directory.Build.props).

    PS: ideally the savings from sccache would offset the "wasted" computing power from not using MSBuild Batching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions