Skip to content

Link flags with clang-cl vs clang #22

@loriab

Description

@loriab

EDIT: I just realized that the issue I described below (specifying clang-cl through cbc.yaml) in a pure C/C++ recipe on staged-recipes produces the same error about /link flag and fails to configure. Filtering out the flag via set "LDFLAGS=%LDFLAGS:/link=%" works fine (effectively same solution as I came to below). So flang has nothing to do with it. Perhaps I'm utterly using the compiler wrong or this issue should be moved to https://github.com/conda-forge/clang-win-activation-feedstock .

2025-04-14T19:26:56.2056605Z (%PREFIX%) %SRC_DIR%\tests>cmake -S. -Bbuild -GNinja -DCMAKE_PREFIX_PATH="%PREFIX%\Library" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=Release" 
2025-04-14T19:26:57.5879410Z -- The CXX compiler identification is Clang 20.1.2 with MSVC-like command-line
2025-04-14T19:26:57.7719227Z -- Detecting CXX compiler ABI info
2025-04-14T19:26:58.1244659Z -- Detecting CXX compiler ABI info - failed
2025-04-14T19:26:58.1246495Z -- Check for working CXX compiler: D:/bld/openorbitaloptimizer-split_1744658708593/_test_env/Library/bin/clang-cl.exe
2025-04-14T19:26:58.4495009Z CMake Error at D:/bld/openorbitaloptimizer-split_1744658708593/_test_env/Library/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:73 (message):
2025-04-14T19:26:58.4496319Z -- Check for working CXX compiler: D:/bld/openorbitaloptimizer-split_1744658708593/_test_env/Library/bin/clang-cl.exe - broken
2025-04-14T19:26:58.4501830Z -- Configuring incomplete, errors occurred!
2025-04-14T19:26:58.4502819Z   The C++ compiler
2025-04-14T19:26:58.4503372Z 
2025-04-14T19:26:58.4504023Z     "D:/bld/openorbitaloptimizer-split_1744658708593/_test_env/Library/bin/clang-cl.exe"
2025-04-14T19:26:58.4504503Z 
2025-04-14T19:26:58.4505065Z   is not able to compile a simple test program.
2025-04-14T19:26:58.4505518Z 
2025-04-14T19:26:58.4506060Z   It fails with the following output:
2025-04-14T19:26:58.4506484Z 
2025-04-14T19:26:58.4507109Z     Change Dir: 'D:/bld/openorbitaloptimizer-split_1744658708593/test_tmp/tests/build/CMakeFiles/CMakeScratch/TryCompile-1tz29h'
2025-04-14T19:26:58.4507740Z     
2025-04-14T19:26:58.4508351Z     Run Build Command(s): D:/bld/openorbitaloptimizer-split_1744658708593/_test_env/Library/bin/ninja.exe -v cmTC_b7a0a
2025-04-14T19:26:58.4509370Z     [1/2] D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\clang-cl.exe  /nologo -TP   /Oi /O2 /GS /Gy /MD -march=nocona -mtune=haswell -fuse-ld=lld /std:c++17 -D_CRT_SECURE_NO_WARNINGS -fms-runtime-lib=dll -fuse-ld=lld  /DWIN32 /D_WINDOWS /GR /EHsc  /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\cmTC_b7a0a.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_b7a0a.dir\ -c -- D:\bld\openorbitaloptimizer-split_1744658708593\test_tmp\tests\build\CMakeFiles\CMakeScratch\TryCompile-1tz29h\testCXXCompiler.cxx
2025-04-14T19:26:58.4511090Z     [2/2] C:\Windows\system32\cmd.exe /C "cd . && D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\cmake.exe -E vs_link_exe --msvc-ver=1929 --intdir=CMakeFiles\cmTC_b7a0a.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\llvm-mt.exe --manifests  -- D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\lld-link.exe /nologo CMakeFiles\cmTC_b7a0a.dir\testCXXCompiler.cxx.obj  /out:cmTC_b7a0a.exe /implib:cmTC_b7a0a.lib /pdb:cmTC_b7a0a.pdb /version:0.0 /machine:x64 /link /DEFAULTLIB:D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\lib\clang\20\lib\windows\clang_rt.builtins-x86_64.lib  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
2025-04-14T19:26:58.4512737Z     FAILED: cmTC_b7a0a.exe 
2025-04-14T19:26:58.4513993Z     C:\Windows\system32\cmd.exe /C "cd . && D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\cmake.exe -E vs_link_exe --msvc-ver=1929 --intdir=CMakeFiles\cmTC_b7a0a.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\llvm-mt.exe --manifests  -- D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\lld-link.exe /nologo CMakeFiles\cmTC_b7a0a.dir\testCXXCompiler.cxx.obj  /out:cmTC_b7a0a.exe /implib:cmTC_b7a0a.lib /pdb:cmTC_b7a0a.pdb /version:0.0 /machine:x64 /link /DEFAULTLIB:D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\lib\clang\20\lib\windows\clang_rt.builtins-x86_64.lib  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
2025-04-14T19:26:58.4516185Z     LINK Pass 1: command "D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\Library\bin\lld-link.exe /nologo CMakeFiles\cmTC_b7a0a.dir\testCXXCompiler.cxx.obj /out:cmTC_b7a0a.exe /implib:cmTC_b7a0a.lib /pdb:cmTC_b7a0a.pdb /version:0.0 /machine:x64 /link /DEFAULTLIB:D:\bld\openorbitaloptimizer-split_1744658708593\_test_env\lib\clang\20\lib\windows\clang_rt.builtins-x86_64.lib /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_b7a0a.dir/intermediate.manifest CMakeFiles\cmTC_b7a0a.dir/manifest.res" failed (exit code 1) with the following output:
2025-04-14T19:26:58.4517398Z     lld-link: error: could not open '/link': no such file or directory

Comment:

Hi, I've been playing around with the flang19 migration PRs on a few feedstocks, in particular conda-forge/gdma-feedstock#10 . Whenever I tried to switch the C/C++ compiler to clang-cl officially (through cbc.yaml) rather than through CMAKE_C_COMPILER=clang-cl, the compiler fails CMake configuration (clang-cl.exe" is not able to compile a simple test program.). I looked into the linker lines added by the various compiler activation feedstocks and tried resetting LDFLAGS in the recipe bld.bat according to their patterns, and I found a variation on the clang-cl one that worked. Comparison of activate LDFLAGS lines and their effect in a flang20 recipe below.

I suspect that the general solution is that the flang activation script in this feedstock needs to choose how to set LDFLAGS depending on whether clang or clang-cl is the target C/C++ compiler.

clang-win-activation-feedstock/.../activate-clang-cl_win-64.bat

::set "LDFLAGS=/link /DEFAULTLIB:%CONDA_PREFIX%\lib\clang\@MAJOR_VER@\lib\windows\clang_rt.builtins-x86_64.lib"
::set "LDFLAGS=/DEFAULTLIB:%CONDA_PREFIX%\lib\clang\@MAJOR_VER@\lib\windows\clang_rt.builtins-x86_64.lib"
set "LDFLAGS=/DEFAULTLIB:%CONDA_PREFIX%\lib\clang\20\lib\windows\clang_rt.builtins-x86_64.lib"

:: outcome
:: WORKS! (after removing /LINK and hard-coding v20)

flang-activation-feedstock/.../activate.bat

set "LDFLAGS=%LDFLAGS% -Wl,-defaultlib:%CONDA_PREFIX:\=/%/lib/clang/@MAJOR_VER@/lib/windows/clang_rt.builtins-x86_64.lib"

:: outcome
:: FAILS: "D:/bld/gdma-split_1744384002874/_build_env/Library/bin/clang-cl.exe" is not able to compile a simple test program.

clang-win-activation-feedstock/.../activate-clang_win-64.bat

set "LDFLAGS=-nostdlib -Wl,-defaultlib:%CONDA_PREFIX:\=/%/lib/clang/@MAJOR_VER@/lib/windows/clang_rt.builtins-x86_64.lib"

:: outcome
:: ALLOWS compiler and library link. on exe: LINK: command "D:\bld\gdma-split_1744384917393\_build_env\Library\bin\lld-link.exe /nologo CMakeFiles\gdmaexe.dir\src\exe.f90.obj /out:gdma.exe /implib:gdma.lib /pdb:gdma.pdb /version:0.0 /machine:x64 -nostdlib -Wl,-defaultlib:D:/bld/gdma-split_1744384917393/_build_env/lib/clang/@MAJOR_VER@/lib/windows/clang_rt.builtins-x86_64.lib /INCREMENTAL:NO /subsystem:console libgdma.lib -libpath:D:/bld/gdma-split_1744384917393/_build_env/Library/lib -libpath:D:/bld/gdma-split_1744384917393/_build_env/Library/lib/clang/20/lib/windows /MANIFEST:EMBED,ID=1" failed (exit code 1) with the following output:
::lld-link: warning: ignoring unknown argument '-nostdlib'
::lld-link: warning: ignoring unknown argument '-Wl,-defaultlib:D:/bld/gdma-split_1744384917393/_build_env/lib/clang/@MAJOR_VER@/lib/windows/clang_rt.builtins-x86_64.lib'

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions