cmake:指定编译器的问题 [英] cmake: problems specifying the compiler

查看:2107
本文介绍了cmake:指定编译器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此CMakeLists.txt档案有问题:

  cmake_minimum_required(VERSION 2.6)

SET(CMAKE_C_COMPILER C:\\MinGW\\bin\\gcc)
SET(CMAKE_CXX_COMPILER C:\\MinGW\\bin\\g ++)

project(cmake_test)

add_executable(a.exe test.cpp)

调用cmake与: cmake -GMinGW Makefiles



我得到:

  c:\cmake_test> cmake -GMinGW Makefiles。 
- C编译器标识是GNU 4.6.1
CMakeFiles / CMakeCCompiler.cmake:1(SET)的CMake警告(dev):
cmake代码中的语法错误在

C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1

当解析字符串

C:\MinGW\bin\gcc

转义序列无效\M

未设置策略CMP0010:错误的变量引用语法是错误。运行
cmake --help-policy CMP0010了解策略详细信息。使用cmake_policy
命令设置策略并禁止此警告。
调用堆栈(最近调用):
CMakeLists.txt:12(project)
此警告是为项目开发人员。使用-Wno-dev来禁止它。

- CXX编译器标识是GNU 4.6.1
在CMakeFiles / CMakeCXXCompiler.cmake:CMakeFiles / CMakeColiler.cmake的CMake警告(dev):
cmake代码中的语法错误

C:/cmake_test/CMakeFiles/CMakeCXXCompiler.cmake:1

当解析字符串

C:\MinGW\bin\g ++

转义序列无效\M

未设置策略CMP0010:错误的变量引用语法是错误。运行
cmake --help-policy CMP0010了解策略详细信息。使用cmake_policy
命令设置策略并禁止此警告。
调用堆栈(最近调用):
CMakeLists.txt:12(project)
此警告是为项目开发人员。使用-Wno-dev来禁止它。

- 检查工作C编译器:C:\MinGW\bin\gcc
Cake的CMake错误:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1(SET):
cmake代码中的语法错误在

C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1

解析字符串时

C :\MinGW\bin\gcc

转义序列无效\M
调用堆栈(最近调用):
CMakeLists.txt:2(PROJECT)

CMake错误:CMAKE_C_COMPILER未设置,在EnableLanguage后
CMake错误:内部CMake错误,TryCompile配置cmake失败
CMake错误:你的C编译器:C:\MinGW\\ \\ bin \gcc。请将CMAKE_C_COMPILER设置为有效的编译器路径或名称。
CMake错误:您的CXX编译器:C:\MinGW\bin\g ++未找到。请将CMAKE_CXX_COMPILER设置为有效的编译器路径或名称。
- 配置不完整,发生错误!

我也尝试过:

  C:\MinGW\bin\g ++ 
/ C / MinGW / bin / g ++

,结果相同。双引号没有帮助。



当然,编译器存在于指定的目录中。



解决方案

您必须使用四个反斜杠才能获得反斜杠在 SET

  SET(CMAKE_C_COMPILER C:\\ \\MinGW\\\\bin\\\\gcc)
SET(CMAKE_CXX_COMPILER C:\\\\MinGW\\\\\\ bin \\\\\g ++)

无论您是否在参数。



由于这是很丑的,最好使用正斜杠:

  SET(CMAKE_C_COMPILER C:/ MinGW / bin / gcc)
SET(CMAKE_CXX_COMPILER C:/ MinGW / bin / g ++)


I have a problem with this CMakeLists.txt file:

cmake_minimum_required(VERSION 2.6)

SET(CMAKE_C_COMPILER C:\\MinGW\\bin\\gcc)
SET(CMAKE_CXX_COMPILER C:\\MinGW\\bin\\g++)

project(cmake_test)

add_executable(a.exe test.cpp)

Calling cmake with: cmake -G "MinGW Makefiles"

I get:

c:\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
CMake Warning (dev) at CMakeFiles/CMakeCCompiler.cmake:1 (SET):
  Syntax error in cmake code at

    C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1

  when parsing string

    C:\MinGW\bin\gcc

  Invalid escape sequence \M

  Policy CMP0010 is not set: Bad variable reference syntax is an error.  Run
  "cmake --help-policy CMP0010" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:12 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The CXX compiler identification is GNU 4.6.1
CMake Warning (dev) at CMakeFiles/CMakeCXXCompiler.cmake:1 (SET):
  Syntax error in cmake code at

    C:/cmake_test/CMakeFiles/CMakeCXXCompiler.cmake:1

  when parsing string

    C:\MinGW\bin\g++

  Invalid escape sequence \M

  Policy CMP0010 is not set: Bad variable reference syntax is an error.  Run
  "cmake --help-policy CMP0010" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  CMakeLists.txt:12 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Check for working C compiler: C:\MinGW\bin\gcc
CMake Error at C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1 (SET):
  Syntax error in cmake code at

    C:/cmake_test/CMakeFiles/CMakeCCompiler.cmake:1

  when parsing string

    C:\MinGW\bin\gcc

  Invalid escape sequence \M
Call Stack (most recent call first):
  CMakeLists.txt:2 (PROJECT)

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
CMake Error: your C compiler: "C:\MinGW\bin\gcc" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:\MinGW\bin\g++" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!

I also tried with:

C:\MinGW\bin\g++
/C/MinGW/bin/g++

with the same result. Double quotes have not been helpful, either.

Of course, the compiler is present in the specified directory.

Thank you for any hint.

解决方案

You have to use four backslashes to get a literal backslash in a SET:

SET(CMAKE_C_COMPILER C:\\\\MinGW\\\\bin\\\\gcc)
SET(CMAKE_CXX_COMPILER C:\\\\MinGW\\\\bin\\\\g++)

This applies whether or not you use quotes around the argument.

Since this is pretty ugly, it's probably better to use forward slashes:

SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)

这篇关于cmake:指定编译器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆