Thread overview
CLI equivalent for 'lib-dir' configuration file option
May 20
axricard
May 20
kinke
May 21
axricard
May 20

Hello,

I'm trying to cross-compile with ldc for a x86_64-windows-msvc target. I followed https://wiki.dlang.org/Cross-compiling_with_LDC (using prebuilt LDC package for C runtime) and it worked just fine. But I'd like to get rid of the ldc2.conf file and have the whole work being done in command line.

The problem is that I can't find a replacement for the 'lib-dir' configuration entry in command line interface. Replacing it with -L=-L$LDC_ROOT/lib-win64/ldc2-1.36.0-windows-x64/ -L=-L$LDC_ROOT/lib-win64/ldc2-1.36.0-windows-x64/mingw doesn't work :

>> ldc2 -mtriple=x86_64-windows -L=-L$LDC_LIB/ -L=-L$LDC_LIB/mingw foo.d -defaultlib=phobos2-ldc,druntime-ldc
lld-link: error: undefined symbol: __chkstk
>>> referenced by druntime-ldc.lib(dmain2.obj):(_d_run_main)
>>> referenced by druntime-ldc.lib(dmain2.obj):(_d_run_main)
>>> referenced by druntime-ldc.lib(dmain2.obj):(_d_run_main2)
>>> referenced 5 more times
Error: linking with LLD failed

it seems that it has to do with this snippet in druntime, but I don't understand what changed between configuration file and cli.

Adding '-L=/alternatename:__chkstk=___chkstk_ms' doesn't solve the problem.

Do you have any idea of how to make it work without ldc2.conf configuration file ?

May 20

Hi! Yeah, there's no CLI equivalent for lib-dirs, which is special. See e.g. the libDirs occurrences in https://github.com/ldc-developers/ldc/blob/master/driver/linker-msvc.cpp. What you are missing in this specific case is linking ldc_rt.builtins.lib, which the compiler only does implicitly if found in lib-dirs, as for other libraries (not guaranteed to be bundled with the LDC installation) and object files.

May 21

On Monday, 20 May 2024 at 15:58:04 UTC, kinke wrote:

>

Hi! Yeah, there's no CLI equivalent for lib-dirs, which is special. See e.g. the libDirs occurrences in https://github.com/ldc-developers/ldc/blob/master/driver/linker-msvc.cpp. What you are missing in this specific case is linking ldc_rt.builtins.lib, which the compiler only does implicitly if found in lib-dirs, as for other libraries (not guaranteed to be bundled with the LDC installation) and object files.

Big thanks !! I totally missed that one. For the records, here is the final command to fully cross-compile and cross-link :

>> LDC_WIN=$LDC_ROOT/lib-win64/ldc2-${LDC_VERSION}-windows-x64/
>> ldc2 -mtriple=x86_64-windows -L=-L$LDC_WIN/lib -L=-L$LDC_WIN/lib/mingw -defaultlib=phobos2-ldc,druntime-ldc -L=-lldc_rt.builtins foo.d