Skip to content

Compiling with Clang on Windows doesn't respect b_vscrt option #14571

@jan-kelemen

Description

@jan-kelemen

Describe the bug
Setting the b_vscrt variable does not have any effect when Clang is used to compile the project.

To Reproduce
meson.build:

project('simple', 'cpp')
executable('myexe', 'source.cpp')

source.cpp:

#include <iostream>

int main()
{
    std::cout << "Hello World\n";
}

native.ini:

[built-in options]
b_vscrt = 'md'
meson setup --native-file native.ini builddir
The Meson build system
Version: 1.8.0
Source dir: D:\git\msn
Build dir: D:\git\msn\builddir
Build type: native build
Project name: simple
Project version: undefined
C++ compiler for the host machine: clang++ (clang 20.1.0 "clang version 20.1.0")
C++ linker for the host machine: clang++ link 14.43.34809.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

simple undefined

  User defined options
    Native files: native.ini

Found ninja-1.12.1 at C:\vim\vim91\ninja.EXE

meson compile -C builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\vim\vim91\ninja.EXE -C D:/git/msn/builddir
ninja: Entering directory `D:/git/msn/builddir'
[2/2] Linking target myexe.exe

This produces an executable that depends only on the kernel32.dll:
Image

Meaning it continues to use the default option for the standard library https://github.com/llvm/llvm-project-release-prs/blob/b3a30dc094050d74a3d5d1a1e2406ca648c7d67d/clang/lib/Driver/ToolChains/Clang.cpp#L4533-L4540 that is the statically linked one.

Expected behavior
b_vscrt value should set -fms-runtime-lib on the compiler command line command line

By changing the native.ini file to:

[built-in options]
cpp_args = ['-fms-runtime-lib=dll']
cpp_link_args = ['-Xlinker', '/NODEFAULTLIB:libcmt']

Compiling produces the executable which links to the expected dynamic library:
Image

Admittedly, there is some weirdness going on, that the link flags need to be added too, but there is an another issue open for that on the LLVM project llvm/llvm-project#129881

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?
    • native build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
    • Windows 11
  • what Python version are you using e.g. 3.8.0
    • Python 3.12.4
  • what meson --version
    • 1.8.0
  • what ninja --version if it's a Ninja build
    • 1.12.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions