Thread overview
Ldc ImportC preprocessor failure (wrong option syntax) on Windows
Solved: Ldc ImportC preprocessor failure (wrong option syntax) on Windows
February 04

Hi,

On my personal machine everything works fine, but our CI build machine suffers from this error:

clang-cl.exe: warning: unknown argument ignored in clang-cl '-target' (did you mean '--target='?) [-Wunknown-argument]
clang-cl.exe: error: no such file or directory: 'x86_64-pc-windows-msvc'

I have the impression that options are given as the Microsoft preprocessor expects them, but that the clang preprocessor is called instead. I think that on my personal machine the Microsoft preprocessor is called, which is also what I would expect, but I don't know of a way to verify that; the workings of ImportC are rather opaque.

My hunch is that LDC doesn't detect the presence of the Microsoft toolchain correctly. I do call vcvarsall.bat x64 prior to invoking ldc. Could there be a global configuration in effect on my personal machine, but not on the CI build machine? One difference is that, although we currently install compilers by unzipping archives and adding to PATH, on my personal machine I have used the Windows Installer in the past, which may have done additional things to configure my system.

Any help is appreciated!

-- Bastiaan.

February 04
On 04/02/2025 10:50 PM, Bastiaan Veelo wrote:
> Hi,
> 
> On my personal machine everything works fine, but our CI build machine suffers from this error:
> ```
> clang-cl.exe: warning: unknown argument ignored in clang-cl '- target' (did you mean '--target='?) [-Wunknown-argument]
> clang-cl.exe: error: no such file or directory: 'x86_64-pc-windows-msvc'
> ```
> 
> I have the impression that options are given as the Microsoft preprocessor expects them, but that the clang preprocessor is called instead. I think that on my personal machine the Microsoft preprocessor is called, which is also what I would expect, but I don't know of a way to verify that; the workings of ImportC are rather opaque.

ldc and dmd have differing behaviors.

https://github.com/ldc-developers/ldc/blob/master/driver/cpreprocessor.cpp

And yes it prefers clang-cl.

Which means this is a bug.

> My hunch is that LDC doesn't detect the presence of the Microsoft toolchain correctly. I do call `vcvarsall.bat x64` prior to invoking ldc. Could there be a global configuration in effect on my personal machine, but not on the CI build machine? One difference is that, although we currently install compilers by unzipping archives and adding to PATH, on my personal machine I have used the Windows Installer in the past, which may have done additional things to configure my system.

Add to PATH, remove old.

That is all you need to do for installation after extraction.

February 04
On Tuesday, 4 February 2025 at 09:57:27 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 04/02/2025 10:50 PM, Bastiaan Veelo wrote:
>> Hi,
>> 
>> On my personal machine everything works fine, but our CI build machine suffers from this error:
>> ```
>> clang-cl.exe: warning: unknown argument ignored in clang-cl '- target' (did you mean '--target='?) [-Wunknown-argument]
>> clang-cl.exe: error: no such file or directory: 'x86_64-pc-windows-msvc'
>> ```
>> 
>> I have the impression that options are given as the Microsoft preprocessor expects them, but that the clang preprocessor is called instead. I think that on my personal machine the Microsoft preprocessor is called, which is also what I would expect, but I don't know of a way to verify that; the workings of ImportC are rather opaque.
>
> ldc and dmd have differing behaviors.
>
> https://github.com/ldc-developers/ldc/blob/master/driver/cpreprocessor.cpp
>
> And yes it prefers clang-cl.
>
> Which means this is a bug.

It could be a bug, but locally I use the same version (ldc 1.39.0) and it works fine... Thanks for pointing to the driver source, maybe I can work out what it is doing.
February 04

On Tuesday, 4 February 2025 at 10:15:23 UTC, Bastiaan Veelo wrote:

>

On Tuesday, 4 February 2025 at 09:57:27 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

On 04/02/2025 10:50 PM, Bastiaan Veelo wrote:

>

Hi,

On my personal machine everything works fine, but our CI build machine suffers from this error:

clang-cl.exe: warning: unknown argument ignored in clang-cl '- target' (did you mean '--target='?) [-Wunknown-argument]
clang-cl.exe: error: no such file or directory: 'x86_64-pc-windows-msvc'

I have the impression that options are given as the Microsoft preprocessor expects them, but that the clang preprocessor is called instead. I think that on my personal machine the Microsoft preprocessor is called, which is also what I would expect, but I don't know of a way to verify that; the workings of ImportC are rather opaque.

ldc and dmd have differing behaviors.

https://github.com/ldc-developers/ldc/blob/master/driver/cpreprocessor.cpp

And yes it prefers clang-cl.

Which means this is a bug.

It could be a bug, but locally I use the same version (ldc 1.39.0) and it works fine... Thanks for pointing to the driver source, maybe I can work out what it is doing.

By adding "dflags-ldc": [ "-v" ], to dub.json I can see that indeed locally cl.exe is employed, and on the failing machine clang-cl.exe. Another difference is that the failing machine is using slightly newer Windows Kits, but that might be unrelated.

Locally:

binary    C:\Users\bastiaan\AppData\Local\Programs\dlang\ldc2\bin\ldc2.exe
version   1.39.0 (DMD v2.109.1, LLVM 18.1.6)
config    C:\Users\bastiaan\AppData\Local\Programs\dlang\ldc2\etc\ldc2.conf (x86_64-pc-windows-msvc)
predefs   Have_pias_hydrotables Have_pias_shared_use Have_pias_nlopt Have_pias_wibu Have_derelict_gl3 Have_gettext Have_pias_epcompat Have_pias_version Have_sarcexchange Have_sbin Have_derelict_util Have_mofile Have_dxml LDC all D_Version2 assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo X86_64 D_InlineAsm_X86_64 D_HardFloat LittleEndian D_LP64 D_PIC D_AVX D_AVX2 Windows Win64 CRuntime_Microsoft CppRuntime_Microsoft LDC_LLVM_1801
[...]
Prepending to environment variables:
  INCLUDE += C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt
  PATH += C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64
MSVC setup took 722 microseconds
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /P /PD /Zc:preprocessor protection\wibu\source\wibucm32.c
/FIC:\Users\bastiaan\AppData\Local\Programs\dlang\ldc2\bin\..\import\importc.h /FiC:\Users\bastiaan\AppData\Local\Temp\itmp-ldc-9f6226\wibucm32.i
wibucm32.c

On the failing machine:

binary    C:\Users\general\AppData\Local\Programs\dlang\ldc2\bin\ldc2.exe
version   1.39.0 (DMD v2.109.1, LLVM 18.1.6)
config    C:\Users\general\AppData\Local\Programs\dlang\ldc2\etc\ldc2.conf (x86_64-pc-windows-msvc)
predefs   Have_pias_hydrotables Have_pias_shared_use Have_pias_nlopt Have_pias_wibu Have_derelict_gl3 Have_gettext Have_pias_epcompat Have_pias_version Have_sarcexchange Have_sbin Have_derelict_util Have_mofile Have_dxml LDC all D_Version2 assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo X86_64 D_InlineAsm_X86_64 D_HardFloat LittleEndian D_LP64 D_PIC D_AVX D_AVX2 Windows Win64 CRuntime_Microsoft CppRuntime_Microsoft LDC_LLVM_1801
[...]
Prepending to environment variables:
  INCLUDE += C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt
  PATH += C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64
MSVC setup took 1184 microseconds
C:\Program Files\LLVM\bin\clang-cl.exe /nologo /P -target x86_64-pc-windows-msvc -Xclang -target-feature -Xclang -16bit-mode -Xclang -target-feature -Xclang -32bit-mode -Xclang -target-feature -Xclang -3dnow -Xclang -target-feature -Xclang -3dnowa -Xclang -target-feature -Xclang +64bit -Xclang -target-feature -Xclang +64bit-mode -Xclang -target-feature -Xclang -adx -Xclang -target-feature -Xclang -aes -Xclang -target-feature -Xclang +allow-light-256-bit -Xclang -target-feature -Xclang -amx-bf16 -Xclang -target-feature -Xclang -amx-complex -Xclang -target-feature -Xclang -amx-fp16 -Xclang -target-feature -Xclang -amx-int8 -Xclang -target-feature -Xclang -amx-tile -Xclang -target-feature -Xclang +avx -Xclang -target-feature -Xclang -avx10.1-256 -Xclang -target-feature -Xclang -avx10.1-512 -Xclang -target-feature -Xclang +avx2 -Xclang -target-feature -Xclang -avx512bf16 -Xclang -target-feature -Xclang -avx512bitalg -Xclang -target-feature -Xclang -avx512bw -Xclang -target-feature -Xclang -avx512cd -Xclang -target-feature -Xclang -avx512dq -Xclang -target-feature -Xclang -avx512er -Xclang -target-feature -Xclang -avx512f -Xclang -target-feature -Xclang -avx512fp16 -Xclang -target-feature -Xclang -avx512ifma -Xclang -target-feature -Xclang -avx512pf -Xclang -target-feature -Xclang -avx512vbmi -Xclang -target-feature -Xclang -avx512vbmi2 -Xclang -target-feature -Xclang -avx512vl -Xclang -target-feature -Xclang -avx512vnni -Xclang -target-feature -Xclang -avx512vp2intersect -Xclang -target-feature -Xclang -avx512vpopcntdq -Xclang -target-feature -Xclang -avxifma -Xclang -target-feature -Xclang -avxneconvert -Xclang -target-feature -Xclang -avxvnni -Xclang -target-feature -Xclang -avxvnniint16 -Xclang -target-feature -Xclang -avxvnniint8 -Xclang -target-feature -Xclang +bmi -Xclang -target-feature -Xclang +bmi2 -Xclang -target-feature -Xclang -branchfusion -Xclang -target-feature -Xclang -ccmp -Xclang -target-feature -Xclang -cf -Xclang -target-feature -Xclang -cldemote -Xclang -target-feature -Xclang -clflushopt -Xclang -target-feature -Xclang -clwb -Xclang -target-feature -Xclang -clzero -Xclang -target-feature -Xclang +cmov -Xclang -target-feature -Xclang -cmpccxadd -Xclang -target-feature -Xclang +crc32 -Xclang -target-feature -Xclang +cx16 -Xclang -target-feature -Xclang +cx8 -Xclang -target-feature -Xclang -egpr -Xclang -target-feature -Xclang -enqcmd -Xclang -target-feature -Xclang +ermsb -Xclang -target-feature -Xclang -evex512 -Xclang -target-feature -Xclang +f16c -Xclang -target-feature -Xclang -false-deps-getmant -Xclang -target-feature -Xclang +false-deps-lzcnt-tzcnt -Xclang -target-feature -Xclang -false-deps-mulc -Xclang -target-feature -Xclang -false-deps-mullq -Xclang -target-feature -Xclang -false-deps-perm -Xclang -target-feature -Xclang +false-deps-popcnt -Xclang -target-feature -Xclang -false-deps-range -Xclang -target-feature -Xclang -fast-11bytenop -Xclang -target-feature -Xclang +fast-15bytenop -Xclang -target-feature -Xclang -fast-7bytenop -Xclang -target-feature -Xclang -fast-bextr -Xclang -target-feature -Xclang -fast-gather -Xclang -target-feature -Xclang -fast-hops -Xclang -target-feature -Xclang -fast-lzcnt -Xclang -target-feature -Xclang -fast-movbe -Xclang -target-feature -Xclang +fast-scalar-fsqrt -Xclang -target-feature -Xclang -fast-scalar-shift-masks -Xclang -target-feature -Xclang +fast-shld-rotate -Xclang -target-feature -Xclang +fast-variable-crosslane-shuffle -Xclang -target-feature -Xclang +fast-variable-perlane-shuffle -Xclang -target-feature -Xclang -fast-vector-fsqrt -Xclang -target-feature -Xclang -fast-vector-shift-masks -Xclang -target-feature -Xclang -faster-shift-than-shuffle -Xclang -target-feature -Xclang +fma -Xclang -target-feature -Xclang -fma4 -Xclang -target-feature -Xclang +fsgsbase -Xclang -target-feature -Xclang -fsrm -Xclang -target-feature -Xclang +fxsr -Xclang -target-feature -Xclang -gfni -Xclang -target-feature -Xclang -harden-sls-ijmp -Xclang -target-feature -Xclang -harden-sls-ret -Xclang -target-feature -Xclang -hreset -Xclang -target-feature -Xclang -idivl-to-divb -Xclang -target-feature -Xclang +idivq-to-divl -Xclang -target-feature -Xclang +invpcid -Xclang -target-feature -Xclang -kl -Xclang -target-feature -Xclang -lea-sp -Xclang -target-feature -Xclang -lea-uses-ag -Xclang -target-feature -Xclang -lvi-cfi -Xclang -target-feature -Xclang -lvi-load-hardening -Xclang -target-feature -Xclang -lwp -Xclang -target-feature -Xclang +lzcnt -Xclang -target-feature -Xclang +macrofusion -Xclang -target-feature -Xclang +mmx -Xclang -target-feature -Xclang +movbe -Xclang -target-feature -Xclang -movdir64b -Xclang -target-feature -Xclang -movdiri -Xclang -target-feature -Xclang -mwaitx -Xclang -target-feature -Xclang -ndd -Xclang -target-feature -Xclang -no-bypass-delay -Xclang -target-feature -Xclang -no-bypass-delay-blend -Xclang -target-feature -Xclang +no-bypass-delay-mov -Xclang -target-feature -Xclang +no-bypass-delay-shuffle -Xclang -target-feature -Xclang +nopl -Xclang -target-feature -Xclang -pad-short-functions -Xclang -target-feature -Xclang +pclmul -Xclang -target-feature -Xclang -pconfig -Xclang -target-feature -Xclang -pku -Xclang -target-feature -Xclang +popcnt -Xclang -target-feature -Xclang -ppx -Xclang -target-feature -Xclang -prefer-128-bit -Xclang -target-feature -Xclang -prefer-256-bit -Xclang -target-feature -Xclang -prefer-mask-registers -Xclang -target-feature -Xclang -prefer-movmsk-over-vtest -Xclang -target-feature -Xclang -prefer-no-gather -Xclang -target-feature -Xclang -prefer-no-scatter -Xclang -target-feature -Xclang -prefetchi -Xclang -target-feature -Xclang -prefetchwt1 -Xclang -target-feature -Xclang -prfchw -Xclang -target-feature -Xclang -ptwrite -Xclang -target-feature -Xclang -push2pop2 -Xclang -target-feature -Xclang -raoint -Xclang -target-feature -Xclang -rdpid -Xclang -target-feature -Xclang -rdpru -Xclang -target-feature -Xclang +rdrnd -Xclang -target-feature -Xclang -rdseed -Xclang -target-feature -Xclang -retpoline -Xclang -target-feature -Xclang -retpoline-external-thunk -Xclang -target-feature -Xclang -retpoline-indirect-branches -Xclang -target-feature -Xclang -retpoline-indirect-calls -Xclang -target-feature -Xclang -rtm -Xclang -target-feature -Xclang +sahf -Xclang -target-feature -Xclang -sbb-dep-breaking -Xclang -target-feature -Xclang -serialize -Xclang -target-feature -Xclang -seses -Xclang -target-feature -Xclang -sgx -Xclang -target-feature -Xclang -sha -Xclang -target-feature -Xclang -sha512 -Xclang -target-feature -Xclang -shstk -Xclang -target-feature -Xclang +slow-3ops-lea -Xclang -target-feature -Xclang -slow-incdec -Xclang -target-feature -Xclang -slow-lea -Xclang -target-feature -Xclang -slow-pmaddwd -Xclang -target-feature -Xclang -slow-pmulld -Xclang -target-feature -Xclang -slow-shld -Xclang -target-feature -Xclang -slow-two-mem-ops -Xclang -target-feature -Xclang -slow-unaligned-mem-16 -Xclang -target-feature -Xclang -slow-unaligned-mem-32 -Xclang -target-feature -Xclang -sm3 -Xclang -target-feature -Xclang -sm4 -Xclang -target-feature -Xclang -soft-float -Xclang -target-feature -Xclang +sse -Xclang -target-feature -Xclang -sse-unaligned-mem -Xclang -target-feature -Xclang +sse2 -Xclang -target-feature -Xclang +sse3 -Xclang -target-feature -Xclang +sse4.1 -Xclang -target-feature -Xclang +sse4.2 -Xclang -target-feature -Xclang -sse4a -Xclang -target-feature -Xclang +ssse3 -Xclang -target-feature -Xclang -tagged-globals -Xclang -target-feature -Xclang -tbm -Xclang -target-feature -Xclang -tsxldtrk -Xclang -target-feature -Xclang -tuning-fast-imm-vector-shift -Xclang -target-feature -Xclang -uintr -Xclang -target-feature -Xclang -use-glm-div-sqrt-costs -Xclang -target-feature -Xclang -use-slm-arith-costs -Xclang -target-feature -Xclang -usermsr -Xclang -target-feature -Xclang -vaes -Xclang -target-feature -Xclang -vpclmulqdq -Xclang -target-feature -Xclang +vzeroupper -Xclang -target-feature -Xclang -waitpkg -Xclang -target-feature -Xclang -wbnoinvd -Xclang -target-feature -Xclang -widekl -Xclang -target-feature -Xclang +x87 -Xclang -target-feature -Xclang -xop -Xclang -target-feature -Xclang +xsave -Xclang -target-feature -Xclang -xsavec -Xclang -target-feature -Xclang +xsaveopt -Xclang -target-feature -Xclang -xsaves -Xclang -dD -Wno-builtin-macro-redefined protection\wibu\source\wibucm32.c /FIC:\Users\general\AppData\Local\Programs\dlang\ldc2\bin\..\import\importc.h /FiC:\Users\general\AppData\Local\Temp\itmp-ldc-b2ae43\wibucm32.i
clang-cl.exe: warning: unknown argument ignored in clang-cl '-target' (did you mean '--target='?) [-Wunknown-argument]
clang-cl.exe: error: no such file or directory: 'x86_64-pc-windows-msvc'
protection\wibu\source\sentinel.d(64,8): Error: C:\Program Files\LLVM\bin\clang-cl.exe failed with status: 1
protection\wibu\source\sentinel.d(64,8):        C preprocessor failed for file 'protection\wibu\source\wibucm32.c'

So while the invocation of clang-cl may be buggy, if I can make LDC on the CI machine to select Microsoft cl instead, I would be good.

-- Bastiaan.

February 04
On Tuesday, 4 February 2025 at 10:15:23 UTC, Bastiaan Veelo wrote:
> It could be a bug, but locally I use the same version (ldc 1.39.0) and it works fine...

version 1.40.0 (DMD v2.110.0, LLVM 19.1.3) has the same issue.

February 04

On Tuesday, 4 February 2025 at 10:54:12 UTC, Bastiaan Veelo wrote:

>

C:\Program Files\LLVM\bin\clang-cl.exe /nologo /P -target

Found it. The CI machine had LLVM installed, where it found clang-cl.exe. After uninstalling LLVM, cl.exe from Microsoft is used instead, which works.

-- Bastiaan.

February 04
On Tuesday, 4 February 2025 at 09:57:27 UTC, Richard (Rikki) Andrew Cattermole wrote:

> Which means this is a bug.

Reported https://github.com/ldc-developers/ldc/issues/4834

Thanks!

-- Bastiaan.