简体   繁体   中英

CMake can not find g++ compiler on Windows

I have a CMake project I want to compile with g++. The project compiles and runs on Linux. Now I am trying to get it working on Windows.

For that reason, I installed MinGW and added it to the PATH and I am using Git Bash. In order to force CMake to use g++ I added these env variables:

CC = C:\MinGW\bin\gcc
CXX = C:\MinGW\bin\g++

printenv 的 Git Bash 输出

But when I run CMake it does not detect any compilers and tells me:

-- The C compiler identification is unkown
-- The CXX compiler identification is unkown

CMake 找不到 C 和 CXX 编译器

I created a super basic example on github which I would like to get running on Windows + MinGw: https://github.com/jodo/Basic-CMake-Project

How can I use the env variables in windows to force CMake to use g++ and gcc compiler?

I needed to add -G "MinGW Makefiles" to the CMake command.

I check if I am on Windows and if yes, I add the parameter to the CMake command in the shell script. I also need to use mingw32-make instead of make when I am on Windows.

There are some other issues now, but it resolves the issue/question I have posted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM