www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linking not working properly Windows 11

reply bauss <jacobbauss gmail.com> writes:
Fresh install of DMD and when trying to use ex. std.file from 
Phobos I get the following linking error: (I can trigger 
different ones depending on modules imported etc.)

```
lld-link: error: undefined symbol: tzset
```

I assume it has something to do with the C runtime or something, 
but everything should be setup correct, so maybe some path or 
something that is incorrect that I may need to modify? I have no 
idea what I need to do however.

I am using dub as well, so basically compiling using:

```
dub build -a=x86_64
```

Is there anything I am missing or what should I do? Currently D 
is unusable for me on my new machine because of this.

If anybody knows how I can just get things to work, it seems like 
D never works out of the box, which is very unfortunate.

This is literally my file:

```d
module main;

import std.file : readText, exists, write;

void main() {}
```

It's as minimal as an example as I can give pretty much.

A similar issue was with C++ runtime libraries such as libcmt.lib 
not being linked and I ended up having to move the files manually 
to my project folder, as I don't know how to fix it properly as 
there aren't any clear instructions anywhere on how to fix 
invalid paths etc. or what to do when linking just doesn't find 
the files despite them existing.

If anyone can help me fix this then I will be very grateful.
Nov 05 2022
next sibling parent bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote:
 ```
 lld-link: error: undefined symbol: tzset
 ```
I don't know if this is relevant, so I will just put it here just in case: ``` lld-link: error: undefined symbol: tzset
 referenced by 
 phobos64.lib(timezone_151f_37a.obj):(_D3std8datetime8timezone9LocalTime9singletonFNeZ9__lambda3FNbNiNfZb)
Error: linker exited with status 1 ```
Nov 05 2022
prev sibling next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
Try ldc, if that works then its just a missing library that needs to be 
linked against regarding MS CRT.
Nov 05 2022
next sibling parent bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole 
wrote:
 Try ldc, if that works then its just a missing library that 
 needs to be linked against regarding MS CRT.
I will give it a try
Nov 05 2022
prev sibling parent reply bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole 
wrote:
 Try ldc, if that works then its just a missing library that 
 needs to be linked against regarding MS CRT.
Using LDC doesn't seem to work either, it has similar linking problems. ``` lld-link: error: undefined symbol: fileno
 referenced by 
 druntime-ldc.lib(dmain2.obj):(_d_print_throwable)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File4syncMFNeZv)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File13windowsHandleMFNdZPv)
 referenced 18 more times
lld-link: error: undefined symbol: execv
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process6execv_FIAyaIAQfZi)
lld-link: error: undefined symbol: execve
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execve_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: execvp
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execvp_FIAyaIAQfZi)
lld-link: error: undefined symbol: execvpe
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process8execvpe_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: tzset
 referenced by 
 phobos2-ldc.lib(timezone.obj):(_D3std8datetime8timezone9LocalTime9singletonFNeZ12__dgliteral4MFNaNbNiNfZOb)
Error: linking with LLD failed ldc2 failed with exit code 1. ``` Not sure what to do at this point.
Nov 05 2022
next sibling parent reply Hipreme <msnmancini hotmail.com> writes:
On Saturday, 5 November 2022 at 14:14:16 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole 
 wrote:
 Try ldc, if that works then its just a missing library that 
 needs to be linked against regarding MS CRT.
Using LDC doesn't seem to work either, it has similar linking problems. ``` lld-link: error: undefined symbol: fileno
 referenced by 
 druntime-ldc.lib(dmain2.obj):(_d_print_throwable)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File4syncMFNeZv)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File13windowsHandleMFNdZPv)
 referenced 18 more times
lld-link: error: undefined symbol: execv
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process6execv_FIAyaIAQfZi)
lld-link: error: undefined symbol: execve
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execve_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: execvp
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execvp_FIAyaIAQfZi)
lld-link: error: undefined symbol: execvpe
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process8execvpe_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: tzset
 referenced by 
 phobos2-ldc.lib(timezone.obj):(_D3std8datetime8timezone9LocalTime9singletonFNeZ12__dgliteral4MFNaNbNiNfZOb)
Error: linking with LLD failed ldc2 failed with exit code 1. ``` Not sure what to do at this point.
Just posted the other day how to use the MSVC Linker on windows. Using LLD is quite complicated in my experience because I was getting a lot of undefined symbols from the libcmt. Check this post: https://forum.dlang.org/thread/frixfbbucsbgcrsvmjtf forum.dlang.org Remember that for using the MSVC Linker you will need to have visual studio build tools on your PC (or install the visual studio with desktop development with C++). Then you can modify your `sc.ini` and it should work.
Nov 05 2022
parent reply bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote:
 On Saturday, 5 November 2022 at 14:14:16 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 13:42:08 UTC, rikki cattermole 
 wrote:
 Try ldc, if that works then its just a missing library that 
 needs to be linked against regarding MS CRT.
Using LDC doesn't seem to work either, it has similar linking problems. ``` lld-link: error: undefined symbol: fileno
 referenced by 
 druntime-ldc.lib(dmain2.obj):(_d_print_throwable)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File4syncMFNeZv)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File13windowsHandleMFNdZPv)
 referenced 18 more times
lld-link: error: undefined symbol: execv
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process6execv_FIAyaIAQfZi)
lld-link: error: undefined symbol: execve
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execve_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: execvp
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execvp_FIAyaIAQfZi)
lld-link: error: undefined symbol: execvpe
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process8execvpe_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: tzset
 referenced by 
 phobos2-ldc.lib(timezone.obj):(_D3std8datetime8timezone9LocalTime9singletonFNeZ12__dgliteral4MFNaNbNiNfZOb)
Error: linking with LLD failed ldc2 failed with exit code 1. ``` Not sure what to do at this point.
Just posted the other day how to use the MSVC Linker on windows. Using LLD is quite complicated in my experience because I was getting a lot of undefined symbols from the libcmt. Check this post: https://forum.dlang.org/thread/frixfbbucsbgcrsvmjtf forum.dlang.org Remember that for using the MSVC Linker you will need to have visual studio build tools on your PC (or install the visual studio with desktop development with C++). Then you can modify your `sc.ini` and it should work.
I have both VS 2019 and 2022, but only 2019 has c++ build tools etc. I assume that should be fine? So I will try this now and see how goes. Currently having some trouble getting it to work, but probably because I am editing sc.ini wrong. Is it possible you could post your sc.ini so I can compare with mine? I get an error like the following when linking: ``` Linking... Error: can't run 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64', check PATH C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. ``` I put this in sc.ini under [Environment] and [Environment64] ``` LINKCMD=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64 ```
Nov 05 2022
next sibling parent reply Hipreme <msnmancini hotmail.com> writes:
On Saturday, 5 November 2022 at 19:19:09 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote:
 [...]
I have both VS 2019 and 2022, but only 2019 has c++ build tools etc. I assume that should be fine? [...]
You forgot to put \link.exe in the path
Nov 05 2022
parent bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 22:53:33 UTC, Hipreme wrote:
 On Saturday, 5 November 2022 at 19:19:09 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote:
 [...]
I have both VS 2019 and 2022, but only 2019 has c++ build tools etc. I assume that should be fine? [...]
You forgot to put \link.exe in the path
I was totally blind-sided by that. It seems to work, except for a couple dub packages that I can't get working, I'm going to assume obsolete api calls to the win api, but overall it works like 90%.
Nov 06 2022
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Saturday, 5 November 2022 at 19:19:09 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 14:54:52 UTC, Hipreme wrote:
 On Saturday, 5 November 2022 at 14:14:16 UTC, bauss wrote:
 On Saturday, 5 November 2022 at 13:42:08 UTC, rikki 
 cattermole wrote:
 Try ldc, if that works then its just a missing library that 
 needs to be linked against regarding MS CRT.
Using LDC doesn't seem to work either, it has similar linking problems. ``` lld-link: error: undefined symbol: fileno
 referenced by 
 druntime-ldc.lib(dmain2.obj):(_d_print_throwable)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File4syncMFNeZv)
 referenced by 
 phobos2-ldc.lib(stdio.obj):(_D3std5stdio4File13windowsHandleMFNdZPv)
 referenced 18 more times
lld-link: error: undefined symbol: execv
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process6execv_FIAyaIAQfZi)
lld-link: error: undefined symbol: execve
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execve_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: execvp
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process7execvp_FIAyaIAQfZi)
lld-link: error: undefined symbol: execvpe
 referenced by 
 phobos2-ldc.lib(process.obj):(_D3std7process8execvpe_FIAyaIAQfIQeZi)
lld-link: error: undefined symbol: tzset
 referenced by 
 phobos2-ldc.lib(timezone.obj):(_D3std8datetime8timezone9LocalTime9singletonFNeZ12__dgliteral4MFNaNbNiNfZOb)
Error: linking with LLD failed ldc2 failed with exit code 1. ``` Not sure what to do at this point.
Just posted the other day how to use the MSVC Linker on windows. Using LLD is quite complicated in my experience because I was getting a lot of undefined symbols from the libcmt. Check this post: https://forum.dlang.org/thread/frixfbbucsbgcrsvmjtf forum.dlang.org Remember that for using the MSVC Linker you will need to have visual studio build tools on your PC (or install the visual studio with desktop development with C++). Then you can modify your `sc.ini` and it should work.
I have both VS 2019 and 2022, but only 2019 has c++ build tools etc. I assume that should be fine? So I will try this now and see how goes. Currently having some trouble getting it to work, but probably because I am editing sc.ini wrong. Is it possible you could post your sc.ini so I can compare with mine? I get an error like the following when linking: ``` Linking... Error: can't run 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64', check PATH C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. ``` I put this in sc.ini under [Environment] and [Environment64] ``` LINKCMD=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64 ```
Manually editing / moving files is not recommended for Visual Studio installs I recommend the following: - Uninstall both version of VS - Reboot - Install the latest version of VS + sdk - Reboot - Reinstall DMD just to make sure
Nov 05 2022
parent bauss <jacobbauss gmail.com> writes:
On Sunday, 6 November 2022 at 03:59:55 UTC, ryuukk_ wrote:
 Manually editing / moving files is not recommended for Visual 
 Studio installs
The manual editing was not for visual studio but for dmd to set a different linker.
Nov 06 2022
prev sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
I've looked up three of those names, they are all deprecated.

I'm wondering if Microsoft have removed them.
Nov 05 2022
prev sibling next sibling parent ryuukk_ <ryuukk.dev gmail.com> writes:
On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote:
 Fresh install of DMD and when trying to use ex. std.file from 
 Phobos I get the following linking error: (I can trigger 
 different ones depending on modules imported etc.)

 ```
 lld-link: error: undefined symbol: tzset
 ```

 I assume it has something to do with the C runtime or 
 something, but everything should be setup correct, so maybe 
 some path or something that is incorrect that I may need to 
 modify? I have no idea what I need to do however.

 I am using dub as well, so basically compiling using:

 ```
 dub build -a=x86_64
 ```

 Is there anything I am missing or what should I do? Currently D 
 is unusable for me on my new machine because of this.

 If anybody knows how I can just get things to work, it seems 
 like D never works out of the box, which is very unfortunate.

 This is literally my file:

 ```d
 module main;

 import std.file : readText, exists, write;

 void main() {}
 ```

 It's as minimal as an example as I can give pretty much.

 A similar issue was with C++ runtime libraries such as 
 libcmt.lib not being linked and I ended up having to move the 
 files manually to my project folder, as I don't know how to fix 
 it properly as there aren't any clear instructions anywhere on 
 how to fix invalid paths etc. or what to do when linking just 
 doesn't find the files despite them existing.

 If anyone can help me fix this then I will be very grateful.
do you have visual studio installed? if so what version? do you have msys installed? is it in your PATH?
Nov 05 2022
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote:
 Fresh install of DMD and when trying to use ex. std.file from 
 Phobos I get the following linking error: (I can trigger 
 different ones depending on modules imported etc.)

 [...]
Im also on Windows 10 and 11 and don't have any problems with dmd
Nov 05 2022
parent bauss <jacobbauss gmail.com> writes:
On Saturday, 5 November 2022 at 19:24:54 UTC, Imperatorn wrote:
 On Saturday, 5 November 2022 at 13:30:43 UTC, bauss wrote:
 Fresh install of DMD and when trying to use ex. std.file from 
 Phobos I get the following linking error: (I can trigger 
 different ones depending on modules imported etc.)

 [...]
Im also on Windows 10 and 11 and don't have any problems with dmd
On my other Windows 10 machine I have never faced problems and I am not sure why I am facing these problems now. I assumed it would work just the same.
Nov 05 2022