title: Compile libgnat to a single LLVM bitcode file
body: <p>How can I compile libgnat to a single LLVM bitcode file? The latest dragonegg release is very old, so I provide a dockerfile to make testing more easy. My end goal is to run Ada in LLVM IR bitcode interpreters.</p>
  
  <p><strong>Dockerfile for the latest official dragonegg release</strong></p>
  
  <pre><code>FROM ubuntu:trusty
  
  COPY . /usr/src/workdir
  WORKDIR /usr/src/workdir
  
  RUN apt-get update \
      &amp;&amp; apt-get -y install build-essential gnat-4.6 libgmp-dev libmpfr-dev libmpc-dev libz-dev gcc-4.6-plugin-dev
      # libz-dev for ld when compiling dragonegg 3.3
      # gcc-4.6-plugin-dev needed when compiling dragonegg 3.3
  
  RUN tar -xzf gcc-4.6.4.tar.gz \
      &amp;&amp; cd gcc-4.6.4 \
      &amp;&amp; mkdir build \
      &amp;&amp; cd build \
      &amp;&amp; CC=gcc-4.6 ../configure --disable-multilib --enable-languages=ada,c,c++ --prefix=/opt/gcc-4.6.4 \
      &amp;&amp; make -j4 \
      &amp;&amp; make install
  
  RUN tar -xzf clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz \
      &amp;&amp; mv clang+llvm-3.3-amd64-Ubuntu-12.04.2 /opt/llvm-3.3
  
  ENV PATH="/opt/llvm-3.3/bin:/opt/gcc-4.6.4/bin:${PATH}"
  
  RUN tar -xzf dragonegg-3.3.src.tar.gz \
      &amp;&amp; mv dragonegg-3.3.src dragonegg-3.3 \
      &amp;&amp; cd dragonegg-3.3 \
      &amp;&amp; GCC=/opt/gcc-4.6.4/bin/gcc make \
      &amp;&amp; cp dragonegg.so /opt/dragonegg.so
  </code></pre>
  
  <p><a href="https://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-4.6.4.tar.gz" rel="nofollow noreferrer">download gcc-4.6.4.tar.gz</a></p>
  
  <p><a href="https://releases.llvm.org/3.3/clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz" rel="nofollow noreferrer">download clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz</a></p>
  
  <p><a href="http://llvm.org/releases/3.3/dragonegg-3.3.src.tar.gz" rel="nofollow noreferrer">download dragonegg-3.3.src.tar.gz</a></p>
  
  <p><strong>hello.adb</strong></p>
  
  <pre><code>with Ada.Text_IO;
  
  procedure Hello is
  begin
     Ada.Text_IO.Put_Line("Hello world from Ada (dragonegg)!");
  end Hello;
  </code></pre>
  
  <p>Run <code>gcc hello.adb -S -O1 -o hello.ll -fplugin=/opt/dragonegg.so -fplugin-arg-dragonegg-emit-ir</code> to compile the hello.adb file. When I try to build the binary with <code>llc -filetype=obj hello.ll</code> and <code>gcc hello.o</code>, I get the following error:</p>
  
  <pre><code>/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
  (.text+0x20): undefined reference to `main'
  hello.o: In function `_ada_hello':
  hello.ll:(.text+0xb): undefined reference to `ada__text_io__put_line__2'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>The error message indicates that the Ada runtime library is missing. Currently, I have no idea, how I can compile the libgnat to a single LLVM bitcode file, so I can link it with the program.</p>