相对输出目录的对象文件名

huangapple go评论70阅读模式
英文:

Relative output directory for Object File Name

问题

If I change Object File Name from $(IntDir) to $(IntDir)%(RelativeDir), Visual Studio gives the following error when compiling:

C:\Program Files\Microsoft Visual Studio22\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(1016,5): error MSB3191: Unable to create directory "C:\Source\Repos\Smia\DpGraphs\out\x64\Debug\C:\Program Files\Microsoft Visual Studio22\Professional\VC\Tools\MSVC.36.32522\modules". The given path's format is not supported.

C:\Source\Repos\Smia\DpGraphs\out\x64\Debug\ is my $(IntDir). It seems that Visual Studio wants to compile some file inside C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules, and %(RelativeDir) is calculated to the full path since it is not relative to my project.

I'm using C++ modules in my project, so that's probably why a file on that path is compiled.

I have files with the same names in my project, so I'd like to keep %(RelativeDir) in the Object File Name.

How can I solve this? I'm using Visual Studio 2022 17.6.0 Preview 4.0.

Edit 1

Here is my project file. As you can see, I'm not including all files using relative paths, so I think the file causing the issue must be included by one of the <import Project"..." /> lines.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{bda3f5fc-e66c-4c4c-a540-6432a8b2a847}</ProjectGuid>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ItemDefinitionGroup>
    <ClCompile>
      <LanguageStandard>stdcpplatest</LanguageStandard>
      <ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
    </ClCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="DirectedGraph\DirectedGraph.ixx" />
    <ClCompile Include="DirectedGraph\Edge.cpp" />
    <ClCompile Include="DirectedGraph\Edge.ixx" />
    <ClCompile Include="DirectedGraph\Graph.cpp" />
    <ClCompile Include="DirectedGraph\Graph.ixx" />
    <ClCompile Include="DirectedGraph\GraphTypes.ixx" />
    <ClCompile Include="DirectedGraph\Node.cpp" />
    <ClCompile Include="DirectedGraph\Node.ixx" />
    <ClCompile Include="NestableGraph\Edge.cpp" />
    <ClCompile Include="NestableGraph\Edge.ixx" />
    <ClCompile Include="NestableGraph\Graph.cpp" />
    <ClCompile Include="NestableGraph\Graph.ixx" />
    <ClCompile Include="NestableGraph\GraphTypes.ixx" />
    <ClCompile Include="NestableGraph\NestableGraph.ixx" />
    <ClCompile Include="NestableGraph\Node.cpp" />
    <ClCompile Include="NestableGraph\Node.ixx" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Edit 2

I was able to find out which files are included by full path:

  • C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules\std.ixx.obj
  • C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules\std.compat.ixx.obj

Edit 3

I've tried explicitly including the two files causing issues in my project file. The idea was that I could then override Object File Name for only those files. But then the files are just included twice and the issue persists.

英文:

相对输出目录的对象文件名

If I change Object File Name from $(IntDir) to $(IntDir)%(RelativeDir), Visual Studio gives the following error when compiling:

C:\Program Files\Microsoft Visual Studio22\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(1016,5): error MSB3191: Unable to create directory "C:\Source\Repos\Smia\DpGraphs\out\x64\Debug\C:\Program Files\Microsoft Visual Studio22\Professional\VC\Tools\MSVC.36.32522\modules". The given path's format is not supported.

C:\Source\Repos\Smia\DpGraphs\out\x64\Debug\ is my $(IntDir). It seems that Visual Studio wants to compile some file inside C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules, and %(RelativeDir) is calculated to the full path since it is not relative to my project.

I'm using C++ modules in my project, so that's probably why a file on that path is compiled.

I have files with the same names in my project, so I'd like to keep %(RelativeDir) in the Object File Name.

How can I solve this? I'm using Visual Studio 2022 17.6.0 Preview 4.0.

Edit 1

Here is my project file. As you can see, I'm not including all files using relative paths, so I think the file causing the issue must be included by one of the <import Project"..." /> lines.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{bda3f5fc-e66c-4c4c-a540-6432a8b2a847}</ProjectGuid>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ItemDefinitionGroup>
    <ClCompile>
      <LanguageStandard>stdcpplatest</LanguageStandard>
      <ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
    </ClCompile>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="DirectedGraph\DirectedGraph.ixx" />
    <ClCompile Include="DirectedGraph\Edge.cpp" />
    <ClCompile Include="DirectedGraph\Edge.ixx" />
    <ClCompile Include="DirectedGraph\Graph.cpp" />
    <ClCompile Include="DirectedGraph\Graph.ixx" />
    <ClCompile Include="DirectedGraph\GraphTypes.ixx" />
    <ClCompile Include="DirectedGraph\Node.cpp" />
    <ClCompile Include="DirectedGraph\Node.ixx" />
    <ClCompile Include="NestableGraph\Edge.cpp" />
    <ClCompile Include="NestableGraph\Edge.ixx" />
    <ClCompile Include="NestableGraph\Graph.cpp" />
    <ClCompile Include="NestableGraph\Graph.ixx" />
    <ClCompile Include="NestableGraph\GraphTypes.ixx" />
    <ClCompile Include="NestableGraph\NestableGraph.ixx" />
    <ClCompile Include="NestableGraph\Node.cpp" />
    <ClCompile Include="NestableGraph\Node.ixx" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

Edit 2

I was able to find out which files are included by full path:

  • C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules\std.ixx.obj
  • C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32522\modules\std.compat.ixx.obj

Edit 3

I've tried explicitly including the two files causing issues in my project file. The idea was that I could then override Object File Name for only those files. But then the files are just included twice and the issue persists.

答案1

得分: 2

On Visual Studio 17.8 Preview 1.0, disabling Build ISO C++23 Standard Library Modules doesn't seem to be enough anymore. The workaround I found was to add <EnableStdModules>false</EnableStdModules> to any top-level <PropertyGroup> inside the project file or a property sheet.

For example, at the top of the project file:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <EnableStdModules>false</EnableStdModules>
    </PropertyGroup>

    [... rest of the file]

For future reference

The error I get is:

> 1>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(1016,5): error MSB3191: Unable to create directory "C:\some\directory\C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.32919\modules". The given path's format is not supported.

There's two properties available from the UI for projects/property sheets:

  • Build ISO C++23 Standard Library Modules, which sets <BuildStlModules>true</BuildStlModules>
  • Enable Experimental C++ Standard Library Modules, which sets <EnableModules>true</EnableModules>

I enabled diagnostic verbosity for MSBuild to figure out where the directory gets added to the list of directories that need to be created: Tools menu, Options; expand Project and Solutions/Build And Run, set MSBuild project build output verbosity to Diagnostic.

I searched for 14.38.32919\modules in the build output and found this:

1>Target "ComputeStdModulesCompileInputs" in file "C:\Program Files\Microsoft Visual Studio22\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets":
1>  Set Property: EnableStdModules=true
1>  Added Item(s): LibraryManifests=C:\Program Files\Microsoft Visual Studio22\Preview\VC\Tools\MSVC.38.32919\modules\modules.json

Notice the EnableStdModules=true, which doesn't correspond to either property from the UI. Adding this property manually to the project file or a property sheet fixes it.

英文:

On Visual Studio 17.8 Preview 1.0, disabling Build ISO C++23 Standard Library Modules doesn't seem to be enough anymore. The workaround I found was to add <EnableStdModules>false</EnableStdModules> to any top-level <PropertyGroup> inside the project file or a property sheet.

For example, at the top of the project file:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <EnableStdModules>false</EnableStdModules>
    </PropertyGroup>

    [... rest of the file]

For future reference

The error I get is:

> 1>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(1016,5): error MSB3191: Unable to create directory "C:\some\directory\C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.38.32919\modules". The given path's format is not supported.

There's two properties available from the UI for projects/property sheets:

  • Build ISO C++23 Standard Library Modules, which sets <BuildStlModules>true</BuildStlModules>
  • Enable Experimental C++ Standard Library Modules, which sets <EnableModules>true</EnableModules>

I enabled diagnostic verbosity for MSBuild to figure out where the directory gets added to the list of directories that need to be created: Tools menu, Options; expand Project and Solutions/Build And Run, set MSBuild project build output verbosity to Diagnostic.

I searched for 14.38.32919\modules in the build output and found this:

1>Target "ComputeStdModulesCompileInputs" in file "C:\Program Files\Microsoft Visual Studio22\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets":
1>  Set Property: EnableStdModules=true
1>  Added Item(s): LibraryManifests=C:\Program Files\Microsoft Visual Studio22\Preview\VC\Tools\MSVC.38.32919\modules\modules.json

Notice the EnableStdModules=true, which doesn't correspond to either property from the UI. Adding this property manually to the project file or a property sheet fixes it.

答案2

得分: 1

The solution turned out to be disabling Build ISO C++23 Standard Library Modules:

相对输出目录的对象文件名

英文:

The solution turned out to be disabling Build ISO C++23 Standard Library Modules:

相对输出目录的对象文件名

答案3

得分: 0

RelativeDir is not itself necessarily a relative path. It's whatever the Include path attribute is set to. If the Include is absolute, so too will RelativeDir be.

英文:

RelativeDir is not itself necessarily a relative path. It's whatever the Include path attribute is set to. If the Include is absolute, so too will RelativeDir be.

huangapple
  • 本文由 发表于 2023年4月19日 21:45:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055294.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定