CMake编译器无法编译简单的测试程序

发布于 2025-01-10 05:56:18 字数 1928 浏览 0 评论 0原文

我正在尝试在 Windows 11 x64 上设置 cmake

我正在使用 MinGW Makefilesmake.exe 进行构建。我使用 Cygwin 安装了编译器和 make。编译器是本机编译器。

我的 CMakeLists.txt 包含以下内容:

cmake_minimum_required(VERSION 3.20)

project(hello CXX)
add_executable(hello main.cpp)

build 目录中,我运行以下命令:
cmake -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=make ..

我得到的输出:

    -- The CXX compiler identification is GNU 11.2.0
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - failed
    -- Check for working CXX compiler: C:/cygwin64/bin/g++.exe
    -- Check for working CXX compiler: C:/cygwin64/bin/g++.exe - broken
    CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
      The C++ compiler
    
        "C:/cygwin64/bin/g++.exe"

  is not able to compile a simple test program.
 It fails with the following output:

    Change Dir: C:/Users/username/Projects/test/build/CMakeFiles/CMakeTmp

    Run Build Command(s):make -f Makefile cmTC_2f478/fast && make  -f CMakeFiles\cmTC_2f478.dir\build.make CMakeFiles/cmTC_2f478.dir/build
    'mTC_2f478.dir' is not recognized as an internal or external command,
    operable program or batch file.
    make: *** [Makefile:126: cmTC_2f478/fast] Error 1





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


-- Configuring incomplete, errors occurred!
See also "C:/Users/username/Projects/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/username/Projects/test/build/CMakeFiles/CMakeError.log".

编译器的安装路径位于 PATH 中。

> where.exe g++
C:\cygwin64\bin\g++.exe

我还尝试使用 g++.exe main -o main.cpp 构建 hello world 并且工作正常。

I'm trying to setup cmake on Windows 11 x64.

I'm using MinGW Makefiles and make.exe for the building. I installed the compiler and make using Cygwin. The compiler is a native compiler.

My CMakeLists.txt contains the following:

cmake_minimum_required(VERSION 3.20)

project(hello CXX)
add_executable(hello main.cpp)

Inside the build directory I run the following command:
cmake -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=make ..

The output I get:

    -- The CXX compiler identification is GNU 11.2.0
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - failed
    -- Check for working CXX compiler: C:/cygwin64/bin/g++.exe
    -- Check for working CXX compiler: C:/cygwin64/bin/g++.exe - broken
    CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
      The C++ compiler
    
        "C:/cygwin64/bin/g++.exe"

  is not able to compile a simple test program.
 It fails with the following output:

    Change Dir: C:/Users/username/Projects/test/build/CMakeFiles/CMakeTmp

    Run Build Command(s):make -f Makefile cmTC_2f478/fast && make  -f CMakeFiles\cmTC_2f478.dir\build.make CMakeFiles/cmTC_2f478.dir/build
    'mTC_2f478.dir' is not recognized as an internal or external command,
    operable program or batch file.
    make: *** [Makefile:126: cmTC_2f478/fast] Error 1





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


-- Configuring incomplete, errors occurred!
See also "C:/Users/username/Projects/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/username/Projects/test/build/CMakeFiles/CMakeError.log".

The path the compiler is installed is in PATH.

> where.exe g++
C:\cygwin64\bin\g++.exe

Also I tried building a hello world using g++.exe main -o main.cpp and worked fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文