如何正确设置CMakeLists.txt文件? [英] How do I correctly set a CMakeLists.txt file?

查看:765
本文介绍了如何正确设置CMakeLists.txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的C ++测试项目,并按如下所示编写了CMakeLists.txt文件;

I have a simple C++ test project and wrote my CMakeLists.txt file as follows;

 cmake_minimum_required(VERSION 2.8)

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

 project(simpleTest)
 add_executable(main main.cpp)

当我尝试运行CMake GUI时生成到MinGW的生成器,我得到以下错误消息:

When i try to run CMake GUI an set generator to MinGW i get the following error message:

The C compiler identification is GNU 4.6.1
The CXX compiler identification is GNU 4.6.1
Check for working C compiler: C:/MinGW/bin/gcc
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: Internal CMake error, TryCompile configure of cmake failed
Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
  program.

  It fails with the following output:



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


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!

我使用的是Windows 7 64位操作系统,我在cmd上确认了这一点;
G ++ --version提供G ++(GCC)4.6.1。

I'm on Windows 7 64 bit and i confirmed on cmd that; G++ --version gives G++ (GCC) 4.6.1.

我在做什么错了?

推荐答案

对不起,但这似乎未在您指定的位置安装编译器。另请参见此处为什么应避免在CMakeLists中设置编译器.txt

Sorry but this looks like the compiler is not installed where you specified. Also see here why you should avoid setting the compiler in CMakeLists.txt

所以我将删除它们,清除cmake缓存,在调用CMake之前设置环境变量CC和CXX,然后重试。

So I'd remove those, clear the cmake cache, set the environment variables CC and CXX before calling CMake and try again.

这篇关于如何正确设置CMakeLists.txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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