# CheckTypeSize fails with mingw cross compiler

**URL:** https://discourse.cmake.org/t/checktypesize-fails-with-mingw-cross-compiler/10599
**Category:** Development
**Created:** [April 6, 2024, 2:09pm UTC](https://discourse.cmake.org/t/checktypesize-fails-with-mingw-cross-compiler/10599 "2024-04-06T14:09:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![HerrNamenlos123](https://discourse.cmake.org/user_avatar/discourse.cmake.org/herrnamenlos123/32/4473_2.png) [@HerrNamenlos123](https://discourse.cmake.org/u/HerrNamenlos123)
#### Post date: [April 6, 2024, 2:09pm UTC](https://discourse.cmake.org/t/checktypesize-fails-with-mingw-cross-compiler/10599/1 "2024-04-06T14:09:24Z")

</div>

I am running into an issue, trying to compile libcurl in GitHub CI with mingw-w64. It turned out that the issue is not specific to curl, but happens directly with mingw:

I am directly in a `ubuntu:latest` docker container. I install `g++-mingw-w64-x86-64` using apt and try to build a simple program:

CMakeLists.txt:

```cmake
cmake_minimum_required(VERSION 3.16)
project(test LANGUAGES C CXX)

include(CheckTypeSize)
check_type_size(size_t sizet)

```

And configure it:

```bash
cmake . -B build -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++

```

It fails with the following output:

```auto
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc - works
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ - works
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
CMake Error at /usr/local/lib/python3.8/dist-packages/cmake/data/share/cmake-3.29/Modules/CheckTypeSize.cmake:146 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/test/build/CMakeFiles/CheckTypeSize/sizet.bin'

  because:

    No such file or directory (input)

  Recorded try_compile output location doesn't exist:

    /test/build/CMakeFiles/CMakeScratch/TryCompile-lXSj87/cmTC_f2ef9

Call Stack (most recent call first):
  /usr/local/lib/python3.8/dist-packages/cmake/data/share/cmake-3.29/Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
  CMakeLists.txt:5 (check_type_size)

-- Configuring incomplete, errors occurred!
root@1e03e2b8deb5:/test#

```

Apparently others have had similar issues:

> <https://stackoverflow.com/questions/74162633/problem-compiling-from-source-opencv-with-mvsc2019-in-64-bit-version>

> [@CHECK\_TYPE\_SIZE regression in CMake-3.25.0](https://discourse.cmake.org/t/check-type-size-regression-in-cmake-3-25-0/6923):
>
> When configuring DCMTK project CHECK\_TYPE\_SIZE function started to fail when switched to CMake-3.25.0, on Windows, using VS 2022, x64. It works well when using CMake-3.24.3. Multiple other people have reported the same issue with CMake-3.25.0 on other projects - see for example OpenCV: [Cmake Compile Error for Opencv 4.5.5 · Issue #22784 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/22784)How to reproduce: Get DCMTK from github.com/DCMTK/dcmtk Configure using VS2022 Problematic CMake command: include (CheckTypeSize)…

However, none of these offer a solution. It seems all of them just say it’s a bug that is fixed in CMake 3.25.

I have tried the same build process listed above using apt version CMake 3.16 and pip-installed versions 3.24, 3.25, 3.28, 3.29 but all of them show the same error.

Is this a bug and if so, is there a workaround? I need both the CheckTypeSize module and MinGW to build libcurl from source, as said…

Thank you for any help!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 27, 2024, 2:45pm UTC](https://discourse.cmake.org/t/checktypesize-fails-with-mingw-cross-compiler/10599/2 "2024-04-27T14:45:46Z")

</div>

Thoughts @brad.king?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 29, 2024, 1:29pm UTC](https://discourse.cmake.org/t/checktypesize-fails-with-mingw-cross-compiler/10599/3 "2024-04-29T13:29:30Z")

</div>

Add `-DCMAKE_SYSTEM_NAME=Windows` to tell CMake that you’re cross-compiling to Windows.
