如何使CMake使用Mingw-w64 gcc/g ++? [英] How can I make CMake use Mingw-w64 gcc/g++?

查看:194
本文介绍了如何使CMake使用Mingw-w64 gcc/g ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windwos上尝试使Mingw-w64与CMake一起使用,因为我的MSVC根本不起作用(使用Windows10 64bit.)

I am on Windwos trying to get Mingw-w64 to work with CMake since my MSVC is somehow not working at all (using Windows10 64bit.

基本上,我添加参数 -DCMAKE_CXX_COMPILER ="C:/MinGW-w64/mingw64/bin/g ++.exe" -DCMAKE_C_COMPILER ="C:/MinGW-w64/mingw64/bin/gcc.exe" 我对CMake的调用,该调用将设置相应的编译器.

Basically I add the arguments -DCMAKE_CXX_COMPILER="C:/MinGW-w64/mingw64/bin/g++.exe" -DCMAKE_C_COMPILER="C:/MinGW-w64/mingw64/bin/gcc.exe" to my call to CMake which sets the corresponding compiler.

但是我得到这些错误:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "C:/MinGW-w64/mingw64/bin/gcc.exe"

  is not able to compile a simple test program.

我怎样才能使它正常工作?

How could I get this to work?

推荐答案

为MinGW(和MinGW-w64)生成makefile的最简单方法是使用适当的CMake生成器.只需调用cmake即可

The simplest way to generate makefiles for MinGW (and MinGW-w64) is to use the appropriate CMake generator. Just call cmake with

-G "MinGW Makefiles"

无需手动设置DCMAKE_CXX_COMPILER和DCMAKE_C_COMPILER.

no need to set DCMAKE_CXX_COMPILER and DCMAKE_C_COMPILER by hand.

为此,CMake必须找到您的编译器.因此,正如CristiFati指出的那样,此路径必须添加到Windows PATH变量中:

For this to work, CMake must find your compilers. So this path must be added to the windows PATH variable, as CristiFati pointed out:

C:/MinGW-w64/mingw64/bin

要检查PATH是否正确,请启动Windows命令提示符并运行

To check if the PATH is correct, fire up a Windows command prompt and run

where gcc

输出应该(至少)是您刚刚添加到Windows PATH变量的路径.

The output should be (at least) the path you just added to the Windows PATH variable.

这篇关于如何使CMake使用Mingw-w64 gcc/g ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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