how to configure linker on Windows

currently I get this message:

> crystal hello.cr
Error: Cannot locate the .lib files for the following libraries: libcmt,
advapi32, libvcruntime, shell32, ole32, WS2_32, kernel32,
legacy_stdio_definitions, DbgHelp, libucrt

here it says Visual Studio is required:

https://crystal-lang.org/install/on_windows

but here is says you can configure the linker:

so is Visual Studio required or not? if not, how do you get it working with something else?

1 Like

No Windows on sight to test, but basically that PR says that you should be able to replace the default cl.exe with whatever linker you have in your machine by setting CC=<path_to_linker> in the environment variables.

d:\>set CC="d:\Ruby30-x64\msys64\mingw64\bin\ld.exe"

d:\>crystal eval "puts 2+2"
Regex match error: UTF-8 error: byte 2 top bits not 0x80 (ArgumentError)
  from a\crystal\crystal\src\regex\pcre2.cr:276 in 'match_data'
  from a\crystal\crystal\src\regex.cr:614 in 'match_at_byte_index'
  from a\crystal\crystal\src\string.cr:2868 in 'gsub'
  from a\crystal\crystal\src\compiler\crystal\compiler.cr:285 in 'codegen'
  from a\crystal\crystal\src\compiler\crystal\compiler.cr:172 in 'compile:combine_rpath'
  from a\crystal\crystal\src\compiler\crystal\codegen\link.cr:148 in 'compile:combine_rpath'
  from a\crystal\crystal\src\compiler\crystal\command\eval.cr:30 in 'eval'
  from a\crystal\crystal\src\compiler\crystal.cr:11 in '__crystal_main'
  from a\crystal\crystal\src\crystal\main.cr:141 in 'main'
  from a\crystal\crystal\src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\Windows\System32\KERNEL32.DLL +97236 in 'BaseThreadInitThunk'
  from C:\Windows\SYSTEM32\ntdll.dll +446161 in 'RtlUserThreadStart'
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

so linker is configurable, but mingw won’t work out of box