how to build LDC2 on linux x86_64

Jens Mueller jens.k.mueller at gmx.de
Tue Mar 8 16:31:43 PST 2011


Jason E. Aten wrote:
> Let's add any comments to this protocol on this, it's own thread, rather
> than on the old thread, to encapsulate and localize -- so as to make it
> easier to find and replicate installion.
> 
> Thanks.
> 
> - Jason
> 
> On Tue, Mar 8, 2011 at 2:15 AM, Jens Mueller <jens.k.mueller at gmx.de> wrote,
> on the old thread titled "LLVM 3.0 type system changes"
> 
> > Can you talk me through the building process? I tried it a week ago but
> > with no success. Can you post the necessary steps on this list or to me
> > in private?
> >
> 
> I can try to sketch the important aspects, but obviously this protocol
> hasn't been tested very widely, so feel free to post back any refinements.
> Even better if you want to patch the repositories.  Some of these may be out
> of order, especially the CMakeCache.txt edits, so if anything goes wrong,
> check the variables mentioned below in CMakeCache.txt, and that your
> ldc2.conf is correct. Those are the most important two control files.
> 
> I'll start a new thread with a new title to make this easy to find, and more
> on topic.
> 
> I. Acknowledgements
> 
> Heavy credit for this is due to mrmonday on #ldc who guided me and
> graciously offered assistance.  Errors and typos are mine alone.
> 
> 
> II. Protocol: Building LDC2 on Linux x86_64
>     Version: 07 March 2011
> 
> 
> Prereqs: cmake, git, hg, llvm2.8 from source already installed (package
> installs of llvm2.8 might work too, I don't know).
> 
> # 1) Check out ldc2, druntime, and phobos2:
> $ hg clone https://bitbucket.org/prokhin_alexey/ldc2
> $ cd ldc2
> $ git clone https://github.com/AlexeyProkhin/druntime
> $ git clone https://github.com/AlexeyProkhin/phobos
> 
> 
> # 2) Configure (apparently you can also use ccmake with gui, but I
> didn't)$ cmake .

I do here
$ cmake -DD_VERSION:STRING=2 -DRUNTIME_DIR=druntime -DPHOBOS2_DIR=phobos -DDEFAULT_TARGET=x86_64-pc-linux-gnu .
to avoid the next step and doing it one step.
I had to add -DDEFAULT_TARGET=x86_64-pc-linux-gnu.

> # 3) Fix up the CMakeCache.txt file:
> 
> # 3 a) edit CMakeCache.txt by hand, and set D_VERSION to 2, as on
> these two lines:
> ...
> 
> //D language version - will originally be set to 1, change it to 2 like this:
> D_VERSION:STRING=2
> 
> ...
> 
> # 3 b) check on the variables mentioned in 3 d). I don't think that
> they will be present yet, but
> if they aren't, it can't hurt to fix them now as well.
> 
> # 3 c) make (this should hopefully build bin/ldc2 now )
> 
> $ make

Did that and it works.

> # there will be some const warnings, but the build finishes for me.
> 
> # 3 d) edit CMakeCache.txt again (it will have changed/had appendixes
> now I think) and fix these two variables:
> 
> 
> ...
> //runtime source dir
> RUNTIME_DIR:PATH=/home/jaten/pkg/ldc2/ldc2/druntime
> ...
> //phobos2 source dir
> PHOBOS2_DIR:PATH=/home/jaten/pkg/ldc2/ldc2/phobos
> ...
> 
> # 4) modify your your .bashrc to set PATH to include ./bin in front of
> everything else
> 
> echo "export PATH=`pwd`/bin:\$PATH" >> ~/.bashrc
> .  ~/.bashrc
> which ldc2 # should show the one in ./bin now
> 
> 
> # 5) build druntime and phobos with the command: make phobos2
> 
> 
> $ make phobos2

Works here as well.

> # 6) edit   ./bin/ldc2.conf so that it points to the right places.  Here is
> a copy of mine that seems to work. The point of the editing is to make sure
> that paths are correct, especially the third -I (Include line), which was
> often wrong out of the box when I was working with it.
> 
> jaten at dfw:~$ cat ldc2.conf
> // This configuration file uses libconfig.
> // See http://www.hyperrealm.com/libconfig/ for syntax details.
> 
> // The default group is required
> default:
> {
>     // 'switches' holds array of string that are appends to the command line
>     // arguments before they are parsed.
>     switches = [
> 
>  "-I/home/jaten/pkg/llvm+lldb+ldc/prokhin_alexeys_ldc2/ldc2/druntime/import",
> 
>  "-I/home/jaten/pkg/llvm+lldb+ldc/prokhin_alexeys_ldc2/ldc2/druntime/src",
>         "-I/home/jaten/pkg/llvm+lldb+ldc/prokhin_alexeys_ldc2/ldc2/phobos/",
> 
>  "-L-L/home/jaten/pkg/llvm+lldb+ldc/prokhin_alexeys_ldc2/ldc2/runtime/../lib",
>         "-defaultlib=phobos2",
>         "-debuglib=phobos2"
>     ];
> };
> jaten at dfw:~$

Was generated like this for me.

> # 7) Finished.  Test and note variances from the protocol above.
> 
> 
> III. Appendix: Troubleshooting notes
> 
> If anything goes wrong, in my experience it was due to the settings in
> either CMakeCache.txt, or in ./bin/ldc2.conf  Those are the two places I
> would look at first when troubleshooting.
> 
> A) When you edit the CMakeCache.txt, be sure to check that PHOBOS2_DIR gets
> set to ./phobos and not ../druntime
> 
> # example that works:
> jaten at dfw:~$ cat CMakeCache.txt.afarm_works_ldc2 | grep PHOBOS2_DIR
> PHOBOS2_DIR:PATH=/home/jaten/pkg/llvm+lldb+ldc/prokhin_alexeys_ldc2/ldc2/phobos
> 
> # example that DOES NOT work:
> jaten at dfw:~$ cat CMakeCache.txt.dfw_notwork_ldc2 | grep PHOBOS2_DIR
> PHOBOS2_DIR:PATH=/home/jaten/pkg/ldc2/ldc2/../druntime
> 
> 
> B) Be sure in CMakeCache.txt you have these three variables set correctly,
> with obvious edits for your paths, not mine:
> 
> ...
> //D language version
> D_VERSION:STRING=2
> ...
> //runtime source dir
> RUNTIME_DIR:PATH=/home/jaten/pkg/ldc2/ldc2/druntime
> ...
> //phobos2 source dir
> PHOBOS2_DIR:PATH=/home/jaten/pkg/ldc2/ldc2/phobos
> 
> 
> Good luck!

Thank you. I just compiled a Hello World using ldc2. For me compiling
ldc2 boils down to:

$ hg clone https://bitbucket.org/prokhin_alexey/ldc2
$ cd ldc2
$ git clone http://github.com/AlexeyProkhin/druntime
$ git clone http://github.com/AlexeyProkhin/phobos
$ cmake -DD_VERSION:STRING=2 -DRUNTIME_DIR=druntime -DPHOBOS2_DIR=phobos -DDEFAULT_TARGET=x86_64-pc-linux-gnu .
$ make phobos2

Setting DEFAULT_TARGET to i686-pc-linux-gnu for building 32-bit binaries
does not work for me. Because then ldc2 ignores the compiled libphobos2
for linking.
$ ./bin/ldc2 ~/hello.d
/usr/bin/ld: skipping incompatible /home/jkm/local/build/ldc2/runtime/../lib/libphobos2.a when searching for -lphobos2
/usr/bin/ld: cannot find -lphobos2
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

Jens


More information about the Digitalmars-d mailing list