32-bit Windows build

Started by Forestidia86, May 17, 2021, 05:42:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Forestidia86

Lix should build 32bit binaries with the compiler LDC as well. (--compiler=ldc2 --arch=x86)

I ran into the problem that the linker didn't want to accept the provided 32bit libs and win32.res. No clue why, but with newly build win32.res and fresh nuget libs it worked.

Forestidia86

#1
Still very speculative:

It is possible that OPTLINK (32bit Linker for dmd) doesn't like the MVS Nuget .libs and lld-link (ldc-linker) doesn't like the from the mingw github DLLS via implib created .libs of Allegro 32bit.

Further remarks:
Caveat for the by DAllegro github provided create_import_libs.bat: It will create from an allegro_xxx-debug-5.2.dll an allegro_xxx.lib.
This is good if you want to use debugging libraries. But if you don't want them but just regular libraries, be sure to have no allegro_xxx-debug-5.2.dll in the directory where you use the batch file since your non-debugging .libs will likely be overridden by debugging .libs.

The debugging libraries (allegro_xxx-debug-5.2.dlls) create an allegro.log when the app runs and need further mingw dependencies.

Simon

Thanks for the investigation.

I'd like to support Windows 32-bit and 64-bit builds, both with DMD and LDC. If I have to offer 3 or 4 convenience archives with Allegro/enet .lib/.dlls, so be it. It's good to have the other compiler as fallback.

-- Simon

Forestidia86

#3
Quote from: Forestidia86 on June 03, 2021, 06:53:13 PM
Still very speculative:

It is possible that OPTLINK (32bit Linker for dmd) doesn't like the MVS Nuget .libs and lld-link (ldc-linker) doesn't like the from the mingw github DLLS via implib created .libs of Allegro 32bit.

It seems that the Nuget .libs are actually .a files (ar archives) that could confuse rather old OPTLINK.

Edit:

Needs to be retested:
The mingw archive has an lib folder with .dll.a-files. If you rename the necessary ones to .lib, ldc 1.24 has a problem with sehsafe since the provided build uses the dwarf exception handler. You can turn sehsafe off by adding the linkerflag '-sehsafe:no' and then it builds/links.
The via implib from the dll created .libs don't seem to work with ldc.

Forestidia86

#4
For the lib problem see as well Allegro 32bit (Edit: topics merged).
For win32.res: In the current stable master there should already be a working win32.res.

Forestidia86

dmd seems to have undergone changes concerning the linking of 32bit binaries. This has yet to be confirmed, but I tested a bit with v2.103.1-dirty.

dmd seems now even with --arch=x86 build 32bitmscoff-builds. Optlink doesn't understand these, so lld-link is used, which is also the linker for ldc.

For reference:
https://dlang.org/changelog/2.086.0.html#dmd-mscoff-default (dub --arch=x86 still uses optlink (-m32 switch for dmd compiler))
https://dlang.org/changelog/2.099.0.html#fix18964 (-m32 now builds 32bitmscoff)
https://forum.dlang.org/post/pvckfcxxntzwzfubkeze@forum.dlang.org (forum topic about incompatibility mscoff and optlink)

Should it turn out to be the case, that dmd now uses lld-link for 32bit by default like ldc as well, then the build notes need to be rewritten. Especially the provided libraries have to be unified to the ldc ones. The dmd ones for 32bit (for the needs of optlink) are then not relevant anymore. Furthermore dub.json has to be adjusted, so that the line '"lflags-windows-x86-dmd": ["-L/subsystem:windows"],' is removed and the flag for 64bit dmd build is used generally for dmd. Maybe no distinction between dmd and ldc is needed anymore.

Forestidia86

#6
To build with optlink you can pass the argument --arch=x86_omf (--compiler=dmd). Unfortunately I get linking errors:

Linking lix
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6
Warning 2: File Not Found C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6
5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib
Warning 2: File Not Found 5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined _al_init
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro55color13ALLEGRO_COLOR11__xopEqualsMxFKxSQBxQBrQBoZb
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro55color13ALLEGRO_COLOR9__xtoHashFNbNeKxSQBwQBqQBnZk
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro55color13ALLEGRO_COLOR6__initZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro56events13ALLEGRO_EVENT6__initZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro55mouse19ALLEGRO_MOUSE_STATE6__initZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro56system14al_run_allegroFMDFZiZi
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D4core8internal4hash__T6hashOfTE3std8encoding3BOMZQBbFNaNbNiNeMxEQBhQBgQBaZk
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D4core8internal5array13concatenation__T14_d_arraycatnTXTAaTAxaTQeZQBbFNaNbNeQrQtZQz
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D4core8internal5array13concatenation__T14_d_arraycatnTXTAaTAxaTQeTQkZQBeFNaNbNeQuQwQBbZQBf
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro57allegro12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro513allegro_audio12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro513allegro_color12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro512allegro_font12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro513allegro_image12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro518allegro_primitives12__ModuleInfoZ
C:\Users\...\AppData\Local\dub\cache\lix\~master\build\application-debug-VXgIcPQCnhYfa1jeg97RIQ\lix.obj(lix)
Error 42: Symbol Undefined __D8allegro511allegro_ttf12__ModuleInfoZ
Error: linker exited with status 17
Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.


Errors may be connected to Warning 2: File Not Found C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6
5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib
The file is there but optlink doesn't seem to recognize.

Reference to similiar bug: https://github.com/CyberShadow/Digger/issues/71

Simon

Thanks for digging into this.

If newer DMD versions (for a few years already?) link with lld-link instead of optlink, we should support that fully, and ditch support for ancient DMD versions that link with optlink. I'll rewrite the Windows build notes accordingly.

Happily, the main way to build Lix on Windows is with LDC (instead of DMD), and LDC building/linking will not be affected. DMD is mainly useful for working with the Lix source code; DMD offers the speediest compilation.

-- Simon

Forestidia86

#8
The main problem concerning the linker error with optlink is that the '+'  of the path C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6+5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib is not recognized and treated as two lines, with the second starting after the '+'.

Compare:
C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6
Warning 2: File Not Found C:\Users\...\AppData\Local\dub\cache\allegro\4.0.6
5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib
Warning 2: File Not Found 5.2.0\build\no-libs-debug-BjwtnovUaJZmlnbyKnG51g\dallegro5.lib

The workaround is to rename the folder, get the linking recipe via dub --vverbose --arch=x86_omf --compiler=dmd and then copy and change the recipe concerning the name of the folder by hand. (For suppression of console add the line "lflags-windows-x86_omf-dmd": ["-L/subsystem:windows"], in dub.json.)

Forestidia86

Since the argument --arch=x86 builds now 32bitmscoff, the libs for the x86 dmd build have to go in the lib32mscoff folder to be recognized instead of the lib folder.

Forestidia86

In future versions of dmd the -m32omf switch will no longer be supported. That means linking with optlink is not viable anymore. (cf. merged pull request Kill off OMF support)