msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

A segmentation error occurred while building cpp files on windows using cmake and g++ #21786

Open MOYUtianming opened 2 weeks ago

MOYUtianming commented 2 weeks ago

Description / Steps to reproduce the issue

brief

add_definitions(
    "--save-temps"
) 

and set_target_properties(<target>PROPERTIES CXX_STANDARD 20)

can't be used at the same time when i compile with g++.

but building with clang is not matter.

version

g++ version:

g++.exe (Rev1, Built by MSYS2 project) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clang version:

clang version 18.1.8
Target: x86_64-w64-windows-gnu
Thread model: posix

code

#include <stdio.h>
int main() {
  return 0;
}

error message

[main] 正在生成文件夹: d:/workspace/reference/opensource/c_cmake_workbench/build 
[build] 正在启动生成
[proc] 执行命令: "C:/Program Files/CMake/bin/cmake.exe" --build d:/workspace/reference/opensource/c_cmake_workbench/build --config Debug --target all --
[build] [1/4  25% :: 0.105] Scanning D:/workspace/reference/opensource/c_cmake_workbench/case/general_test.cpp for CXX dependencies
[build] [2/4  50% :: 0.179] Generating CXX dyndep file case/CMakeFiles/general_test.dir/CXX.dd
[build] [3/4  75% :: 0.328] Building CXX object case/CMakeFiles/general_test.dir/general_test.cpp.obj
[build] FAILED: case/CMakeFiles/general_test.dir/general_test.cpp.obj 
[build] D:\Tools\msys64\mingw64\bin\g++.exe  -ID:/workspace/reference/opensource/c_cmake_workbench/code/core/public -g -std=gnu++20   --save-temps -MD -MT case/CMakeFiles/general_test.dir/general_test.cpp.obj -MF case\CMakeFiles\general_test.dir\general_test.cpp.obj.d -fmodules-ts -fmodule-mapper=case\CMakeFiles\general_test.dir\general_test.cpp.obj.modmap -MD -fdeps-format=p1689r5 -x c++ -o case/CMakeFiles/general_test.dir/general_test.cpp.obj -c D:/workspace/reference/opensource/c_cmake_workbench/case/general_test.cpp
[build] 
[build] Segmentation fault
[build]     4 | }
[build]       | ^
[build] Please submit a full bug report, with preprocessed source (by using -freport-bug).
[build] See <https://github.com/msys2/MINGW-packages/issues> for instructions.
[build] ninja: build stopped: subcommand failed.
[proc] 命令“"C:/Program Files/CMake/bin/cmake.exe" --build d:/workspace/reference/opensource/c_cmake_workbench/build --config Debug --target all --”已退出,代码为 1
[driver] 生成完毕: 00:00:00.457
[build] 生成已完成,退出代码为 1

CMakeLists.txt

main CMakeLists.txt

cmake_minimum_required(VERSION 3.30.0)
project(c_cmake_workbench VERSION 0.1.0)

include(CTest)
enable_testing()

add_definitions(
    "--save-temps"
)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/lib/share)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/lib/archive)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/)

include_directories(${PROJECT_SOURCE_DIR}/code/core/public)
add_subdirectory(case)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

sub CMakeLists.txt

add_executable(general_test ./general_test.cpp)
set_target_properties(general_test PROPERTIES CXX_STANDARD 20)

Expected behavior

I hope i can use gcc build code with both --save-temps and c++20 standard;

Actual behavior

I can't use --save-temps and c++20 standard at the both time when I use g++ 14.2.0

Verification

Windows Version

MINGW64_NT-10.0-22631

MINGW environments affected

Are you willing to submit a PR?

No response

MOYUtianming commented 2 weeks ago

cmake version

cmake version 3.30.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
MOYUtianming commented 2 weeks ago

clang build message

[main] 正在生成文件夹: d:/workspace/reference/opensource/c_cmake_workbench/build 
[main] 正在配置项目: c_cmake_workbench 
[proc] 执行命令: D:/Tools/msys64/mingw64/bin/cmake.exe -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:/Tools/msys64/mingw64/bin/clang.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:/Tools/msys64/mingw64/bin/clang++.exe --no-warn-unused-cli -SD:/workspace/reference/opensource/c_cmake_workbench -Bd:/workspace/reference/opensource/c_cmake_workbench/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done (0.3s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: D:/workspace/reference/opensource/c_cmake_workbench/build
[build] 正在启动生成
[proc] 执行命令: D:/Tools/msys64/mingw64/bin/cmake.exe --build d:/workspace/reference/opensource/c_cmake_workbench/build --config Debug --target all --
[build] [1/4  25% :: 0.172] Scanning D:/workspace/reference/opensource/c_cmake_workbench/case/general_test.cpp for CXX dependencies
[build] [2/4  50% :: 0.269] Generating CXX dyndep file case/CMakeFiles/general_test.dir/CXX.dd
[driver] 生成完毕: 00:00:00.383
[build] 生成已完成,退出代码为 0

g++ build message (use cmake installed by pacman)

[main] 正在生成文件夹: d:/workspace/reference/opensource/c_cmake_workbench/build 
[build] 正在启动生成
[proc] 执行命令: D:/Tools/msys64/mingw64/bin/cmake.exe --build d:/workspace/reference/opensource/c_cmake_workbench/build --config Debug --target all --
[build] [1/4  25% :: 0.105] Scanning D:/workspace/reference/opensource/c_cmake_workbench/case/general_test.cpp for CXX dependencies
[build] [2/4  50% :: 0.188] Generating CXX dyndep file case/CMakeFiles/general_test.dir/CXX.dd
[build] [3/4  75% :: 0.330] Building CXX object case/CMakeFiles/general_test.dir/general_test.cpp.obj
[build] FAILED: case/CMakeFiles/general_test.dir/general_test.cpp.obj 
[build] D:\Tools\msys64\mingw64\bin\g++.exe  -ID:/workspace/reference/opensource/c_cmake_workbench/code/core/public -g -std=gnu++20   --save-temps -MD -MT case/CMakeFiles/general_test.dir/general_test.cpp.obj -MF case\CMakeFiles\general_test.dir\general_test.cpp.obj.d -fmodules-ts -fmodule-mapper=case\CMakeFiles\general_test.dir\general_test.cpp.obj.modmap -MD -fdeps-format=p1689r5 -x c++ -o case/CMakeFiles/general_test.dir/general_test.cpp.obj -c D:/workspace/reference/opensource/c_cmake_workbench/case/general_test.cpp
[build] 
[build] Segmentation fault
[build]     4 | }
[build]       | ^
[build] Please submit a full bug report, with preprocessed source (by using -freport-bug).
[build] See <https://github.com/msys2/MINGW-packages/issues> for instructions.
[build] ninja: build stopped: subcommand failed.
[proc] 命令“D:/Tools/msys64/mingw64/bin/cmake.exe --build d:/workspace/reference/opensource/c_cmake_workbench/build --config Debug --target all --”已退出,代码为 1
[driver] 生成完毕: 00:00:00.452
[build] 生成已完成,退出代码为 1
Peter0x44 commented 2 weeks ago

Can you provide the code and a separate compiler command to build outside of cmake?

MOYUtianming commented 2 weeks ago

code

it is the simplest code that can cause the bug, without any other dependencies;


#include<stdio.h>
intmain() {
  return0;
}

command without cmake


g++ ../case/general_test.cpp -g -std=gnu++20 --save-temps -o general_test.bin

it works too, so this segmentation fault maybe directly related to cmake;

file name maybe need to be replaced by yourself;

At 2024-08-29 20:29:48, "Peter0x44" @.***> wrote:

Can you provide the code and a separate compiler command to build outside of cmake?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

MOYUtianming commented 2 weeks ago

MOYUtianming/problem_report (github.com)

I have support the whole project in this repository, I can repeat the bug by the following steps:


<open MINGW64;>

<cd to this project's root dir>

mkdir build

cd build

cmake ..

cmake --build .

by the way, if I use


g++ --save-temps -std=gnu++20 ../case/general_test.cpp -o ./out.bin

the outfile out.bin can be used correctly;

so this error maybe is an error of cmake?

At 2024-08-29 20:29:48, "Peter0x44" @.***> wrote:

Can you provide the code and a separate compiler command to build outside of cmake?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

MOYUtianming commented 2 weeks ago

https://github.com/MOYUtianming/problem_report the whole abnormal project.