如何使用Visual Studio设置$(OutDir),$(TargetName),$(TargetExt)和%(Lib.OutputFile)?

pro*_*eek 17 unit-testing googletest visual-studio

我正在尝试在Visual Studio 2010上构建gtest.转换解决方案文件后,我尝试构建,并收到以下警告消息.

Warning 1   warning MSB8012: 
TargetPath(C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest/Debug\gtest.lib) does not match
the Library's OutputFile property value (C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest\
Debug\gtestd.lib).

This may cause your project to build incorrectly. 
To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property
values match the value specified in %(Lib.OutputFile).  
C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets
Run Code Online (Sandbox Code Playgroud)

消息说我需要设置变量$(OutDir),$(TargetName)以及中$(TargetExt)指定的属性值%(Lib.OutputFile).

我怎么能用Visual Studio(特别是VS 2010)做到这一点?

Han*_*ant 25

我看到了.右键单击gtest项目,Properties,Configuration properties,General.确保选择了Debug配置(左上角组合).将目标名称属性更改为

 $(ProjectName)d
Run Code Online (Sandbox Code Playgroud)

注意添加"d"将名称从gtest更改为gtestd.否则警告是良性的.


小智 8

我认为没有人有正确的答案,我这样解决了:在项目属性页面中,检查是否linker->General->Output file匹配configuration properties->General->target name&configuration properties->General->target extension.

Inherit from parent or project defaults对于所有3个变量,您不需要添加任何"d",当然,更简单的设置.

例:

Linker ? General ? Output File = "myproject.exe"
Run Code Online (Sandbox Code Playgroud)

然后:

Configuration Properties ? General ? Target Name = "myproject"

configuration properties ? General ? Target Extension = ".exe"
Run Code Online (Sandbox Code Playgroud)


Bil*_*eal 4

该警告是虚假的 - 假设您使用的是 Google Test,它工作得很好

不过你可以让它消失。右键单击有问题的项目并选择属性。在左侧的树视图中选择“Librarian”,然后通过单击输出文件旁边的框并选择“从父​​级或项目默认值继承”来更改右侧的“输出文件”项。

  • 这不是正确的答案。这*更改*了输出文件的名称,.lib 的调试和发布版本现在都命名为 gtest。最后构建的任何内容都会覆盖该文件。当 OP 最终将 .lib 的发布版本链接到他想要测试的代码的调试版本时,这给 OP 带来了麻烦。后来他删除了这个问题,我想他已经明白了。 (5认同)
  • @汉斯:不正确。Visual Studio 已将这些文件放在单独的文件夹中。仅当您决定将库复制到单个目录中时才需要额外的“d”。 (2认同)