www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Choosing the correct compiler version

reply Alexander Zhirov <azhirov1991 gmail.com> writes:
Hello everyone
I want to install the `ldc2` compiler on a specific machine 
`i586`:

```sh
~ $ strings /lib/libc.so.6 | grep GLIBC
GLIBC_2.0
GLIBC_2.1
GLIBC_2.1.1
GLIBC_2.1.2
GLIBC_2.1.3
GLIBC_2.2
GLIBC_2.2.1
GLIBC_2.2.2
GLIBC_2.2.3
GLIBC_2.2.4
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_2.18
GLIBC_2.22
GLIBC_2.23
GLIBC_PRIVATE
```

I'm trying to install dmd with my hands in order to build ldc2 
from the sources, but I can't:

```sh
~ $ dmd --version
dmd: /lib/libc.so.6: version `GLIBC_2.28' not found (required by 
dmd)
```

Please tell me which version for the current configuration I can 
use?
Jul 19 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Tuesday, 19 July 2022 at 15:28:44 UTC, Alexander Zhirov wrote:
 I'm trying to install dmd with my hands in order to build ldc2 
 from the sources, but I can't:
I need to build a compiler under x32 in order to compile a program for the same machine. ```sh posix.mak:42: ===== DEPRECATION NOTICE ===== posix.mak:43: ===== DEPRECATION: posix.mak is deprecated. Please use src/build.d instead. posix.mak:44: ============================== dmd -of../generated/build -g build.d dmd: /lib/libc.so.6: version `GLIBC_2.28' not found (required by dmd) posix.mak:111: recipe for target '../generated/build' failed make: *** [../generated/build] Error 1 ```
Jul 19 2022
parent reply jfondren <julian.fondren gmail.com> writes:
On Tuesday, 19 July 2022 at 15:33:59 UTC, Alexander Zhirov wrote:
 On Tuesday, 19 July 2022 at 15:28:44 UTC, Alexander Zhirov 
 wrote:
 I'm trying to install dmd with my hands in order to build ldc2 
 from the sources, but I can't:
I need to build a compiler under x32 in order to compile a program for the same machine. ```sh posix.mak:42: ===== DEPRECATION NOTICE ===== posix.mak:43: ===== DEPRECATION: posix.mak is deprecated. Please use src/build.d instead. posix.mak:44: ============================== dmd -of../generated/build -g build.d dmd: /lib/libc.so.6: version `GLIBC_2.28' not found (required by dmd) posix.mak:111: recipe for target '../generated/build' failed make: *** [../generated/build] Error 1 ```
You can find the release archive linked from https://dlang.org/download.html , after clicking 'Download' by dmd. It's at http://downloads.dlang.org/ You can then go through old versions and, by trial, find one that's old enough to work on your machine, which you can then use to a newer dmd: for x in dmd druntime phobos; do git clone https://github.com/dlang/$x; done export HOST_DMD=path/to/bin32/dmd Finding an old version that works on your machine will be very easy, but for example the random 2016 build that I grabbed was also too old to build dmd master, so you want to prefer a newer build that still works. It's not necessary to build dmd master though: in the worst case, you should be able check out interim releases (look at 'git tag --list', then 'git checkout v2.094.0' for example), build those, then used them to build a newer release. This is all of course a massive PITA, which any extremely nice person could make less of a pain by cataloguing useful versions on the D wiki or by providing their own "good enough to compile master" builds for old architectures. Another option is to get newer glibc onto this system (not installing it, just making it available for dmd. use LD_LIBRARY_PATH). An option that's technically possible but probably even more of a pain than what I've just described is using another machine to cross-compile static 32-bit D binaries that will then work on this machine. I've tried this and run into pretty unpleasant limitations, but I have a guide anyway at https://d.minimaltype.com/index.cgi/wiki?name=statically-linked+binaries , which you can supplement with https://wiki.dlang.org/Cross-compiling_with_LDC to get a 32-bit result. For that matter 'ldc2 -mtriple i686-linux-musl file.d' might be made to work, but I've no idea how to supply the toolchains that it expects. Speaking of toolchains, it might be possible to use a modern server with a modern dmd with an ancient glibc: https://www.lordaro.co.uk/posts/2018-08-26-compiling-glibc.html
Jul 19 2022
next sibling parent kdevel <kdevel vogtner.de> writes:
On Tuesday, 19 July 2022 at 23:19:28 UTC, jfondren wrote:

Thanks for your thorough presentation.

 [...]
 Another option is to get newer glibc onto this system (not 
 installing it, just making it available for dmd. use 
 LD_LIBRARY_PATH).
On older systems the dynamic loader (ld.so) may not execute the binary under the new glibc with the error message "ELF file OS ABI invalid". This is due to the addition of two features to the toolchain (`STB_GNU_UNIQUE`, `STT_GNU_IFUNC`) eleven years ago [0] an application programmer usually does not have to deal with. In this case one needs to start dmd using the loader which accompanies the new glibc. In order to avoid that I use patchelf to set `INTERP` and `RUNPATH` on all binaries in linux/bin64 accordingly.
 [...]
 Speaking of toolchains, it might be possible to use a modern 
 server with a modern dmd with an ancient glibc: 
 https://www.lordaro.co.uk/posts/2018-08-26-compiling-glibc.html
Since glibc is not forward compatible [1] I wonder why the dmd tools are not routinely linked against a long established glibc version. [0] <https://sourceware.org/legacy-ml/binutils/2011-04/msg00107.html> [1] <https://stackoverflow.com/questions/11107263/how-compatible-are-different-versions-of-glibc>
Jul 20 2022
prev sibling parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Tuesday, 19 July 2022 at 23:19:28 UTC, jfondren wrote:
 Finding an old version that works on your machine will be very 
 easy, but for example the random 2016 build that I grabbed was 
 also too old to build dmd master, so you want to prefer a newer 
 build that still works. It's not necessary to build dmd master 
 though: in the worst case, you should be able check out interim 
 releases (look at 'git tag --list', then 'git checkout 
 v2.094.0' for example), build those, then used them to build a 
 newer release.
Yes, you were right! I managed to launch the 2020 version. Now I'm trying to build `ldc2`. I will report on the successes a little later. Thanks!
Jul 20 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Thursday, 21 July 2022 at 05:44:41 UTC, Alexander Zhirov wrote:
 I will report on the successes a little later.
Result: I downloaded and unpacked the binary version of the `dmd` compiler version [2.097.2](http://downloads.dlang.org/releases/2021/dmd.2.097.2.linux.tar.xz), which runs without problems with my `glibc` set. Then I compiled the `GCC` compiler version 9.5.0 from the source code: ```sh wget https://ftp.mpi-inf.mpg.de/mirrors/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-9.5.0/gcc-9.5.0.tar.gz mkdir build-gcc && cd build-gcc ../gcc-9.5.0/configure --prefix=$PWD/../install-gcc --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ make -j16 make install ``` Then I built `LLVM` using this compiler, according to the instructions on the [LDC website](https://wiki.dlang.org/Building_LDC_from_source#Building_LLVM_from_source): ```sh export CC=/root/source/gcc/gcc-install/bin/gcc export CXX=/root/source/gcc/gcc-install/bin/g++ mkdir build-llvm && cd build-llvm cmake ../llvm-10.0.1.src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../install-llvm -DLLVM_BINUTILS_INCDIR=/usr/include -DLLVM_TARGETS_TO_BUILD='X86' -DCOMPILER_RT_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF make -j16 make install ``` And then I built the `ldc` compiler myself, also according to the instructions on the [website](https://wiki.dlang.org/Building_LDC_from_source#Building_LDC_from_source): ```sh git clone --recursive https://github.com/ldc-developers/ldc.git mkdir build-ldc && cd build-ldc cmake ../ldc -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../install-ldc -DLLVM_ROOT_DIR=<PATH_TO_LLVM_INSTALL> -DD_COMPILER=<PATH_TO_DMD_COMPILER_X32> make -j16 make install ``` As a result, I built the `ldc` compiler for my `x32` machine: ```sh LDC - the LLVM D compiler (1.30.0): based on DMD v2.100.1 and LLVM 10.0.1 built with DMD32 D Compiler v2.097.2 Default target: i686-pc-linux-gnu Host CPU: broadwell http://dlang.org - http://wiki.dlang.org/LDC Registered Targets: x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 ``` I hope my guide will be useful to someone who will face the same task. Thank you for your help!
Jul 25 2022
parent Alain De Vos <devosalain ymail.com> writes:
I don't know if this helps but i have to do,
export CC=/usr/local/bin/gcc
with ldc2.
I don't know why it works with gcc but not with llvm/clang.
Aug 03 2022