Trying to cross compile, here is the minimal example CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(hello VERSION 0.0.0 LANGUAGES C)
set(src "${CMAKE_CURRENT_BINARY_DIR}/src/main.c")
file(WRITE "${src}" "int main(){}")
add_executable(${PROJECT_NAME} "${src}")
$ brew install mingw-w64
$ mkdir 'cmake-build-win64-debug' && cd "$_"
$ cmake .. \
-DCMAKE_BUILD_TYPE='Debug' \
-DCMAKE_C_COMPILER='i686-w64-mingw32-gcc' \
-DCMAKE_CXX_COMPILER='i686-w64-mingw32-g++'
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/local/bin/i686-w64-mingw32-gcc - broken
CMake Error at /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/usr/local/bin/i686-w64-mingw32-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: cmake-build-win64-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_f30ca/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_f30ca.dir/build.make CMakeFiles/cmTC_f30ca.dir/build
Building C object CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -o CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -c cmake-build-win64-debug/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_f30ca
/usr/local/Cellar/cmake/3.20.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_f30ca.dir/link.txt --verbose=1
/usr/local/bin/i686-w64-mingw32-gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_f30ca.dir/testCCompiler.c.o -o cmTC_f30ca
/usr/local/Cellar/mingw-w64/8.0.0_4/toolchain-i686/bin/i686-w64-mingw32-ld: Error: unable to disambiguate: -search_paths_first (did you mean --search_paths_first ?)
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_f30ca] Error 1
make: *** [cmTC_f30ca/fast] Error 2
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 "cmake-build-win64-debug/CMakeFiles/CMakeOutput.log".
See also "cmake-build-win64-debug/CMakeFiles/CMakeError.log".
So I tried https://stackoverflow.com/a/54482619, specifically with
-DCMAKE_CXX_LINK_FLAGS='' \
-DHAVE_FLAG_SEARCH_PATHS_FIRST=0
But that didn't fix it. How do I build for Windows from macOS?