www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Windows psapi, linker issues

reply M <nope nope.nope> writes:
When trying to use `import core.sys.windows.psapi : 
GetProcessImageFileNameA`, LDC fails to link with an error 
`lld-link: error: undefined symbol: _GetProcessImageFileNameA 12` 
(LDC distribution 
https://github.com/ldc-developers/ldc/releases/download/v1.13.0/ldc2-1
13.0-windows-x64.7z , "vs2017-win2016" Windows image from Azure pipelines).

Any ideas?
Dec 26 2018
parent reply kinke <noone nowhere.com> writes:
On Wednesday, 26 December 2018 at 12:06:38 UTC, M wrote:
 When trying to use `import core.sys.windows.psapi : 
 GetProcessImageFileNameA`, LDC fails to link with an error 
 `lld-link: error: undefined symbol: 
 _GetProcessImageFileNameA 12` (LDC distribution 
 https://github.com/ldc-developers/ldc/releases/download/v1.13.0/ldc2-1
13.0-windows-x64.7z , "vs2017-win2016" Windows image from Azure pipelines).

 Any ideas?
The error suggests you're targeting Win32 (-m32) but using a Win64-only LDC distribution. The multilib package features 32-bit libs too.
Dec 26 2018
parent reply M <nope nope.nope> writes:
On Wednesday, 26 December 2018 at 12:15:43 UTC, kinke wrote:
 The error suggests you're targeting Win32 (-m32) but using a 
 Win64-only LDC distribution. The multilib package features 
 32-bit libs too.
Using multilib distribution and explicit `--arch=x86_64` in dub, error has simply changed to "lld-link: error: undefined symbol: GetProcessImageFileNameA". Note that other functions (for example, from core.sys.windows.winbase) do seem to link fine.
Dec 26 2018
parent reply kinke <noone nowhere.com> writes:
On Wednesday, 26 December 2018 at 14:22:07 UTC, M wrote:
 Using multilib distribution and explicit `--arch=x86_64` in 
 dub, error has simply changed to "lld-link: error: undefined 
 symbol: GetProcessImageFileNameA". Note that other functions 
 (for example, from core.sys.windows.winbase) do seem to link 
 fine.
That's looking better now. You probably need to link explicitly against psapi.lib for that symbol. According to MSDN (https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getpro essimagefilenamea), newer Windows versions provide a `K32GetProcessImageFileName` function in kernel32.lib, but druntime declares the old one.
Dec 26 2018
parent reply M <nope nope.nope> writes:
On Wednesday, 26 December 2018 at 15:50:31 UTC, kinke wrote:
 That's looking better now. You probably need to link explicitly 
 against psapi.lib for that symbol. According to MSDN 
 (https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getpro
essimagefilenamea), newer Windows versions provide a
`K32GetProcessImageFileName` function in kernel32.lib, but druntime declares
the old one.
Thanks, that helped. Any reason why libraries referenced by druntime are not added to linker flags automatically?
Dec 26 2018
parent kinke <noone nowhere.com> writes:
On Wednesday, 26 December 2018 at 18:51:48 UTC, M wrote:
 Any reason why libraries referenced by druntime are not added 
 to linker flags automatically?
Well, auto-magic needs a `pragma(lib, "psapi")`, which is missing in that file (but I guess appropriate), just like this reference: https://github.com/dlang/druntime/blob/master/src/core/sys/windows/wingdi.d#L13 So please consider opening an upstream (i.e., dlang) PR to prevent similar hassle for other guys.
Dec 26 2018