Skip to content

cmake crate requires linking with libgcc when cross-compiling with clang to x86_64-pc-windows-gnullvm from linux #256

@maia-s

Description

@maia-s

I'm trying to cross-compile the SDL 3 library using llvm-clang targeting x86_64-pc-windows-gnullvm from linux. I've set up the cross-compiler and a toolchain file for cmake, and I can successfully build SDL for windows using these. However, when trying to compile it from a build script with the cmake crate, even when passing the toolchain file to cmake and overriding rust's linker to use lld, I get this error:

  CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
    The C compiler

      "/opt/llvm-mingw/llvm-mingw-ucrt/bin/x86_64-w64-mingw32-clang"

    is not able to compile a simple test program.

    It fails with the following output:

(...)
      FAILED: [code=1] cmTC_aaf08.exe 
      : && /opt/llvm-mingw/llvm-mingw-ucrt/bin/x86_64-w64-mingw32-clang --sysroot=/opt/llvm-mingw/llvm-mingw-ucrt -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-gnu -fuse-ld=lld CMakeFiles/cmTC_aaf08.dir/testCCompiler.c.obj -o cmTC_aaf08.exe -Wl,--out-implib,libcmTC_aaf08.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && :
      lld: error: unable to find library -lgcc
      lld: error: unable to find library -lgcc_eh
      lld: error: unable to find library -lgcc
      lld: error: unable to find library -lgcc_eh
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      ninja: build stopped: subcommand failed.

I haven't found a way to fix it. libgcc isn't available for windows-gnullvm, everything's compiled with clang for windows, and I have no idea where that requirement comes from. Since it works with plain cmake I think the bug is in the cmake crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions