# Incorrect link library flags in mixed C++/ASM project using MSVC with Clang

**URL:** https://discourse.cmake.org/t/incorrect-link-library-flags-in-mixed-c-asm-project-using-msvc-with-clang/15600
**Category:** Development
**Tags:** os:windows, gen:ninja
**Created:** [April 10, 2026, 10:59pm UTC](https://discourse.cmake.org/t/incorrect-link-library-flags-in-mixed-c-asm-project-using-msvc-with-clang/15600 "2026-04-10T22:59:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MEhrn00](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mehrn00/32/6096_2.png) [@MEhrn00](https://discourse.cmake.org/u/MEhrn00)
#### Post date: [April 10, 2026, 10:59pm UTC](https://discourse.cmake.org/t/incorrect-link-library-flags-in-mixed-c-asm-project-using-msvc-with-clang/15600/1 "2026-04-10T22:59:13Z")

</div>

I am experiencing an issue in a mixed C++/ASM project on Windows using MSVC as the C++ compiler and Clang for the assembler.

When configuring a project for Ninja passing `-DCMAKE_ASM_COMPILER=clang`, bare link library names in C++ targets have a `-l` flag prefixed to them but the linker is `link.exe` which does not use `-l` for handling link libraries.

The same issue seems to occur whether `clang` is used with the GNU command-line frontend or `clang-cl` is used with the MSVC command-line frontend.

Here is a simple example to reproduce it.

```CMake
# CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(cmake-issue LANGUAGES CXX ASM)

add_executable(cmake-issue main.cpp)
target_link_libraries(cmake-issue bcrypt)

```

```cpp
// main.cpp
#include <windows.h>
#include <bcrypt.h>

int main() {
  BCryptCreateContext(CRYPT_LOCAL, L"", NULL);
}

```

Using Ninja as the generator and compiling it will yield linking errors.

```auto
PS > cmake -G Ninja -B build -DCMAKE_ASM_COMPILER=clang
-- The CXX compiler identification is MSVC 19.44.35225.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang.exe
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.6s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/User/Documents/cmake-issue/build
PS > cd .\build\
PS .\build> ninja
[2/2] Linking CXX executable cmake-issue.exe
FAILED: cmake-issue.exe 
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --msvc-ver=1944 --intdir=CMakeFiles\cmake-issue.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles/cmake-issue.dir/main.cpp.obj /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -lbcrypt kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles/cmake-issue.dir/main.cpp.obj /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -lbcrypt kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmake-issue.dir/intermediate.manifest CMakeFiles\cmake-issue.dir/manifest.res" failed (exit code 1120) with the following output:
LINK : warning LNK4044: unrecognized option '/lbcrypt'; ignored
main.cpp.obj : error LNK2019: unresolved external symbol BCryptCreateContext referenced in function main
cmake-issue.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
PS .\build>

```

The link command includes `-lbcrypt` when it should be `bcrypt.lib`. The same issue occurs if `clang-cl` is used for the assembler instead of the GNU command-line frontend version.

Removing `ASM` from the list of languages will pass the correct `bcrypt.lib` library in the link command so this only occurs if mixing assembly in a project on Windows.

I have tested this with CMake 3.31 and the latest 4.3.1 versions and they both experience the same behavior.

Figured I should ask here to see if others have experienced this or if there is some underlying issue with how the link command is generated.

---

<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 13, 2026, 1:41pm UTC](https://discourse.cmake.org/t/incorrect-link-library-flags-in-mixed-c-asm-project-using-msvc-with-clang/15600/2 "2026-04-13T13:41:08Z")

</div>

We don’t currently support mixing GNU-like and MSVC-like compiler drivers across languages.

See [CMake Issue 25620](https://gitlab.kitware.com/cmake/cmake/-/work_items/25620).

---

<div class="post-metadata">

### Author: ![MEhrn00](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mehrn00/32/6096_2.png) [@MEhrn00](https://discourse.cmake.org/u/MEhrn00)
#### Post date: [April 14, 2026, 5:32pm UTC](https://discourse.cmake.org/t/incorrect-link-library-flags-in-mixed-c-asm-project-using-msvc-with-clang/15600/3 "2026-04-14T17:32:53Z")

</div>

Thanks for linking the issue on this and I see there have been some recent developments on it!

> …mixing GNU-like and MSVC-like compiler drivers…

Does the GNU-like and MSVC-like in this case refer to the compiler frontend style or the compiler itself? In my case, using MSVC `cl.exe` for the C++ compiler and `clang-cl` for the assembler yields the same result with the extraneous `-l` in the link command but both use MSVC-style command line arguments.

```auto
PS > cmake -G Ninja -B build -DCMAKE_CXX_COMPILER=cl -DCMAKE_ASM_COMPILER=clang-cl
-- The CXX compiler identification is MSVC 19.44.35225.0
-- The ASM compiler identification is Clang with MSVC-like command-line
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.4s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/User/Documents/cmake-issue/build
PS > cd .\build\
PS .\build> ninja
[2/2] Linking CXX executable cmake-issue.exe
FAILED: cmake-issue.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --msvc-ver=1944 --intdir=CMakeFiles\cmake-issue.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmake-issue.dir\main.cpp.obj /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -lbcrypt kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmake-issue.dir\main.cpp.obj /out:cmake-issue.exe /implib:libcmake-issue.dll.a /pdb:cmake-issue.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -lbcrypt kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmake-issue.dir/intermediate.manifest CMakeFiles\cmake-issue.dir/manifest.res" failed (exit code 1120) with the following output:
LINK : warning LNK4044: unrecognized option '/lbcrypt'; ignored
main.cpp.obj : error LNK2019: unresolved external symbol BCryptCreateContext referenced in function main
cmake-issue.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
PS .\build>

```

CMake does detect that both the CXX compiler and ASM compiler use MSVC-style command line arguments and the linker is invoked directly but the link command seems to include a `-l` flag prefix. No GNU-style compilers are enabled for this project so I am a little unsure where that is coming from.

This is not a pressing issue that I can work around but I just wanted to check to see if this is expected behavior or if there is some other underlying issue.

Thanks for the reply.
