使用Visual Studio 2012/2013的CMake出现问题?

3

我使用的Windows 7操作系统下的Visual Studio 2012,但CMake 2.8.10.2无法为我的项目进行配置。

看起来CMake添加了一些不再受Microsoft编译器支持的设置。 LINK : fatal error LNK1117: syntax error in option 'manifest:embed'

我尝试使用一个非常基本的cmake文件,但结果相同。

cmake_minimum_required (VERSION 2.6)
add_executable(test test.cpp)

是否有解决方法?

输出窗口显示:

The C compiler identification is MSVC 17.0.51106.1
The CXX compiler identification is MSVC 17.0.51106.1
Check for working C compiler using: Visual Studio 11
Check for working C compiler using: Visual Studio 11 -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
  11.0/VC/bin/cl.exe" is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: C:/tmp/testCmake/build/CMakeFiles/CMakeTmp



  Run Build Command:C:\PROGRA~2\MICROS~2.0\Common7\IDE\devenv.com
  CMAKE_TRY_COMPILE.sln /build Debug /project cmTryCompileExec3122367237



  Microsoft (R) Microsoft Visual Studio 2012 Version 11.0.51106.1.

  Copyright (C) Microsoft Corp.  All rights reserved.

  1>------ Build started: Project: cmTryCompileExec3122367237, Configuration:
  Debug Win32 ------

  1> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01
  for 80x86

  1> Copyright (C) Microsoft Corporation.  All rights reserved.

  1> 

  1> cl /c /Zi /W3 /WX- /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D
  "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise
  /Zc:wchar_t /Zc:forScope /Fo"cmTryCompileExec3122367237.dir\Debug\\"
  /Fd"C:/tmp/testCmake/build/CMakeFiles/CMakeTmp/Debug/cmTryCompileExec3122367237.pdb"
  /Gd /TC /analyze- /errorReport:prompt /Zm1000 testCCompiler.c

  1> 

  1> testCCompiler.c

  1>LINK : fatal error LNK1117: syntax error in option 'manifest:embed'

  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
  ==========





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):



Configuring incomplete, errors occurred!

我已经在几个项目中使用VS2012超过1个月了。VTK、ITK、DCMTK、GDCM都能够成功构建,我的代码也一样。我正在使用CMake 2.8.10.2。虽然我很少再为32位构建程序了。 - drescherjm
我之前也一直在使用Visual Studio 2012和CMake,没有遇到过问题。几天前我重新安装了Visual Studio并安装了最新的更新,然后问题就出现了。 - jgaa
从错误信息来看:无法找到cl.exe(VS C ++编译器)-您的cl.exe安装在哪里?尝试使用cl进行命令行编译(如此处所述:https://dev59.com/Ymsz5IYBdhLWcg3wfn0x),以确定您的编译器是否正常工作。也许您的VS安装出了问题。 - Vertexwahn
@Vertexwahn,你的说法不正确。编译器已经找到了,但是一个测试编译失败了,并且出现了jgaa给出的错误信息。 - usr1234567
它声明了 Check for working C compiler using: Visual Studio 11 -- broken,这意味着出现了错误。如果简单的测试代码无法编译,则认为编译器已经损坏。我正在使用2.8.10.2和2.8.12.2,并且确认Cmake和VS 2012没有问题。您可以尝试自己编译测试代码,因为manifest:embed本身并没有错。 - Samuel
3个回答

3

CMake 2.8与Visual Studio 2012兼容。

在您提供的日志中,注意到CMake调用Visual Studio 2012,而后者又调用了Visual Studio 2008的编译器(15.x;VS2012的编译器应为17.x):

Microsoft (R) Microsoft Visual Studio 2012 Version 11.0.51106.1.

[...]

1> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86

这可能意味着您的VS2012安装配置为使用VS2008的工具集。这可能也就是在Visual Studio中直接构建时发生的情况。

这可能是由于属性表Microsoft.Cpp.Win32.user.props(如果您正在构建x64,则为Microsoft.Cpp.x64.user.props)意外更改引起的。这些文件位于%LOCALAPPDATA%\Microsoft\MSBuild\v4.0。如果在任何这些属性表中看到VS2008的目录,则这很可能是问题的根源。

要解决此问题,您可以手动编辑该文件(完全删除引用VS2008文件夹的XML元素),或按照此答案中给出的步骤执行:

  1. 在Visual Studio 2012中打开任何C++项目。
  2. 打开查看 -> 其他窗口 -> 属性管理器
  3. 双击Microsoft.Cpp.Win32.user
  4. 进入VC++目录
  5. 已更改的行将加粗。对于所有加粗的行,单击文本字段内部,然后在下拉菜单中选择继承自父级或项目默认值
  6. 单击应用保存,然后关闭对话框。

谢谢。这个解决方案对我也有用,我使用的是Cmake和Visual Studio 2013,尽管我试图编译64位版本。 - Macke

0

这对我没有用。但是我能够删除有问题的文件(C:\Users\\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props),然后Visual Studio会重新创建该文件。这个问题已经解决了,适用于VS2012和2013。


0

我也遇到了错误:

LINK:致命错误LNK1117:选项“manifest:embed”中的语法错误

这发生在Windows 7,Visual Studio 2013 Community下。

我尝试了许多解决方案,唯一有效的方法是完全从计算机中删除Visial Studio 2010。没有其他方法可行。 我追踪到一个问题,在VS2013中,变量$VCInstallDir仍然指向2010安装。这导致了错误的LibarayPath设置和错误的工具链执行(即使我有正确的“PlatformToolset”设置)。

总之:

  1. 您需要在项目中设置正确的“PlatformToolset”设置,并在所有依赖它的库项目中设置相同的设置
  2. 您需要确保使用正确的库目录,通过检查$LibraryPath是否正确,并且除非您直接在项目设置中覆盖它,否则它将取决于$VCInstallDir通过Visual Studio内部自动化,因此也要检查该变量
  3. 要解决问题2,您可能需要删除Visual Studio 2010,因为它会造成混乱,可能没有其他解决方案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接