2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LDCをビルドしてみよう

Last updated at Posted at 2025-12-01

D言語 Wikiにも書いてあるので必要ない気もするのだが、日本語で手順を書いてあることで目に留まる人もいるかと思い書いておく。

まずなにはなくともLDCのレポジトリをcloneしておこう。

git clone --recursive https://github.com/ldc-developers/ldc.git

また今回はLDCをビルドするためのD言語のバイナリはすでにインストール済としておく。

ビルドに利用するLLVM 20はLDCが用意しているものを使う。

curl -fL -o llvm.tar.xz https://github.com/ldc-developers/llvm-project/releases/download/ldc-v20.1.5/llvm-20.1.5-linux-x86_64.tar.xz
tar xf llvm.tar.xz
rm llvm.tar.xz

さっそくldc2バイナリをビルドしよう

$ mkdir build-ldc && cd $_
$ cmake -G Ninja ../ldc \
    -DCMAKE_C_COMPILER=/usr/bin/clang-21 \
    -DCMAKE_CXX_COMPILER=/usr/bin/clang++-21 \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=$PWD/../install-ldc \
    -DLLVM_ROOT_DIR=$PWD/../llvm-20.1.5-linux-x86_64
(snip...)
$ ninja ldc2
(snip..)
[118/118] Linking CXX executable bin/ldc2
 $ ./bin/ldc2 --version| head -1
LDC - the LLVM D compiler (1.42.0-git-3883e04):

もちろんこれだけではなんもできない。

$ ./bin/ldc2 -run ../dlang/hello.d
/usr/bin/ld: /tmp/objtmp-ldc-2a3e59/hello.o: in function `_D4core8internal5array9appending__T18_d_arrayappendcTX_HTAaTaZQBbFNaNbNcNeMNkKQvmbZQBa':
hello.d:(.text._D4core8internal5array9appending__T18_d_arrayappendcTX_HTAaTaZQBbFNaNbNcNeMNkKQvmbZQBa[_D4core8internal5array9appending__T18_d_arrayappendcTX_HTAaTaZQBbFNaNbNcNeMNkKQvmbZQBa]+0x80): undefined reference to `_D4core8internal5array5utils11newCapacityFNaNbmmZm'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1

というわけで標準ライブラリも一緒にビルドしてあげよう。

$ ninja ldc2 libdruntime-ldc.a libphobos2-ldc.a
(snip..)
 ./bin/ldc2 -run ../dlang/hello.d
Hello, World!
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?