title: error while loading shared libraries: libFoundation.so: cannot open shared object file: No such file or directory
body: <p>I'm on a new installed Ubuntu 18.04 machine, installed clang and llvm via apt-get and installed/downloaded Swift from swift.org<br>
  <em>test.swift</em> file:</p>
  
  <pre><code>import Foundation
  
  let s: String = ":)"
  let d: Date = Date()
  print("Hello Foundation! \(s) - \(d)")   
  </code></pre>
  
  <p>If i run</p>
  
  <pre><code>swiftc test.swift -o test &amp;&amp; ./test 
  </code></pre>
  
  <p>it outputs <strong>Hello Foundation! :) - 2018-09-12 08:56:31 +0000</strong> as it should. </p>
  
  <p>Then i generate LLVM bitcode with</p>
  
  <pre><code>swiftc -emit-bc test.swift -o test.bc
  </code></pre>
  
  <p>and executed via <strong>lli</strong>:  </p>
  
  <pre><code>lli \ 
  -load=/usr/local/lib/swift/linux/libFoundation.so
  -load=/usr/local/lib/swift/linux/libswiftCore.so
  -load=/usr/local/lib/swift/linux/libswiftGlibc.so
  -load=/usr/local/lib/swift/linux/libswiftSwiftOnoneSupport.so
   test.bc
  </code></pre>
  
  <p>This outputs the same as above <strong>Hello Foundation! :) - 2018-09-12 08:56:31 +0000</strong></p>
  
  <p>So i took <strong>llc</strong> and compliled it to an object file:</p>
  
  <pre><code>llc -filetype=obj test.bc -o test.o
  </code></pre>
  
  <p>After that i wanted to link this file to an executable with: </p>
  
  <pre><code>ld -L /usr/local/lib/swift/linux/*.so -dynamic-linker /lib64/ld-linux-x86-64.so.2 test.o -o test -e main
  </code></pre>
  
  <p>which produces: </p>
  
  <pre><code>file test  
  test:  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped
  </code></pre>
  
  <p>but if i run it:</p>
  
  <pre><code>.test/: error while loading shared libraries: libFoundation.so: cannot open shared object file: No such file or directory 
  </code></pre>
  
  <p>the strange part comes now:</p>
  
  <pre><code>ldd test
  
  linux-vdso.so.1 (0x00007ffe456fb000)
  libFoundation.so =&gt; not found
  libswiftCore.so =&gt; not found
  libswiftGlibc.so =&gt; not found
  libswiftRemoteMirror.so =&gt; not found
  libswiftSwiftOnoneSupport.so =&gt; not found
  /usr/local/lib/swift/linux/libXCTest.so (0x00007f91f139e000)
  libswiftCore.so =&gt; /usr/local/lib/swift/linux/libswiftCore.so (0x00007f91f0c8c000)
  libswiftGlibc.so =&gt; /usr/local/lib/swift/linux/libswiftGlibc.so (0x00007f91f1390000)
  libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f91f0a6d000)
  libutil.so.1 =&gt; /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f91f086a000)
  libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f91f0666000)
  libFoundation.so =&gt; /usr/local/lib/swift/linux/libFoundation.so (0x00007f91efd2e000)
  libdispatch.so =&gt; /usr/local/lib/swift/linux/libdispatch.so (0x00007f91f12f8000)
  libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007f91ef990000)
  libstdc++.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f91ef602000)
  libgcc_s.so.1 =&gt; /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f91ef3ea000)
  libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f91eeff9000)
  libatomic.so.1 =&gt; /usr/lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f91eedf1000)
  libicuuc.so.60 =&gt; /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f91eea3a000)
  libicui18n.so.60 =&gt; /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007f91ee599000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f91f11c5000)
  libicudata.so.60 =&gt; /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f91ec9f0000)
  libcurl.so.4 =&gt; /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f91ec771000)
  libxml2.so.2 =&gt; /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f91ec3b0000)
  libbsd.so.0 =&gt; /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f91ec19b000)
  librt.so.1 =&gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007f91ebf93000)
  libnghttp2.so.14 =&gt; /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007f91ebd6e000)
  libidn2.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f91ebb51000)
  librtmp.so.1 =&gt; /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f91eb935000)
  libpsl.so.5 =&gt; /usr/lib/x86_64-linux-gnu/libpsl.so.5 (0x00007f91eb727000)
  libssl.so.1.1 =&gt; /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f91eb4bd000)
  libcrypto.so.1.1 =&gt; /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f91eb045000)
  libgssapi_krb5.so.2 =&gt; /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f91eadfa000)
  libldap_r-2.4.so.2 =&gt; /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f91eaba8000)
  liblber-2.4.so.2 =&gt; /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f91ea99a000)
  libz.so.1 =&gt; /lib/x86_64-linux-gnu/libz.so.1 (0x00007f91ea77d000)
  liblzma.so.5 =&gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f91ea557000)
  libunistring.so.2 =&gt; /usr/lib/x86_64-linux-gnu/libunistring.so.2 (0x00007f91ea1d9000)
  libgnutls.so.30 =&gt; /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f91e9e74000)
  libhogweed.so.4 =&gt; /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f91e9c40000)
  libnettle.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f91e9a0a000)
  libgmp.so.10 =&gt; /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f91e9789000)
  libkrb5.so.3 =&gt; /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f91e94b3000)
  libk5crypto.so.3 =&gt; /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f91e9281000)
  libcom_err.so.2 =&gt; /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f91e907d000)
  libkrb5support.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f91e8e72000)
  libresolv.so.2 =&gt; /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f91e8c57000)
  libsasl2.so.2 =&gt; /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f91e8a3c000)
  libgssapi.so.3 =&gt; /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f91e87fb000)
  libp11-kit.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f91e84cc000)
  libtasn1.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f91e82b9000)
  libkeyutils.so.1 =&gt; /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f91e80b5000)
  libheimntlm.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f91e7eac000)
  libkrb5.so.26 =&gt; /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f91e7c1f000)
  libasn1.so.8 =&gt; /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f91e797d000)
  libhcrypto.so.4 =&gt; /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f91e7747000)
  libroken.so.18 =&gt; /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f91e7531000)
  libffi.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f91e7329000)
  libwind.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f91e7100000)
  libheimbase.so.1 =&gt; /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f91e6ef1000)
  libhx509.so.5 =&gt; /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f91e6ca7000)
  libsqlite3.so.0 =&gt; /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f91e699e000)
  libcrypt.so.1 =&gt; /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f91e6766000)
  </code></pre>
  
  <p>all not founded libs like libFoundation.so are listed twice. Once not found and then found.</p>
  
  <p>Why? And could this be the Problem why it don't execute? </p>