加载共享库时出错:libFoundation.so:无法打开共享库文件:没有这样的文件或目录

时间:2018-09-12 09:25:34

标签: swift ubuntu ld

我在新安装的Ubuntu 18.04计算机上,通过apt-get安装了clang和llvm,并从swift.org安装/下载了Swift
test.swift 文件:

import Foundation

let s: String = ":)"
let d: Date = Date()
print("Hello Foundation! \(s) - \(d)")   

如果我跑步

swiftc test.swift -o test && ./test 

它输出 Hello Foundation! :)-应当按2018年12月12日08:56:31 +0000 进行操作。

然后我用

生成LLVM位代码
swiftc -emit-bc test.swift -o test.bc

并通过 lli 执行:

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

与上面的 Hello Foundation输出相同。 :)-2018-09-12 08:56:31 +0000

所以我拿了 llc 并将其编译为目标文件:

llc -filetype=obj test.bc -o test.o

之后,我想将此文件链接到具有以下内容的可执行文件:

ld -L /usr/local/lib/swift/linux/*.so -dynamic-linker /lib64/ld-linux-x86-64.so.2 test.o -o test -e main

产生:

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

但是如果我运行它:

.test/: error while loading shared libraries: libFoundation.so: cannot open shared object file: No such file or directory 

奇怪的部分现在出现了:

ldd test

linux-vdso.so.1 (0x00007ffe456fb000)
libFoundation.so => not found
libswiftCore.so => not found
libswiftGlibc.so => not found
libswiftRemoteMirror.so => not found
libswiftSwiftOnoneSupport.so => not found
/usr/local/lib/swift/linux/libXCTest.so (0x00007f91f139e000)
libswiftCore.so => /usr/local/lib/swift/linux/libswiftCore.so (0x00007f91f0c8c000)
libswiftGlibc.so => /usr/local/lib/swift/linux/libswiftGlibc.so (0x00007f91f1390000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f91f0a6d000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f91f086a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f91f0666000)
libFoundation.so => /usr/local/lib/swift/linux/libFoundation.so (0x00007f91efd2e000)
libdispatch.so => /usr/local/lib/swift/linux/libdispatch.so (0x00007f91f12f8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f91ef990000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f91ef602000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f91ef3ea000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f91eeff9000)
libatomic.so.1 => /usr/lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f91eedf1000)
libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f91eea3a000)
libicui18n.so.60 => /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007f91ee599000)
/lib64/ld-linux-x86-64.so.2 (0x00007f91f11c5000)
libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f91ec9f0000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f91ec771000)
libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f91ec3b0000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f91ec19b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f91ebf93000)
libnghttp2.so.14 => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007f91ebd6e000)
libidn2.so.0 => /usr/lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f91ebb51000)
librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f91eb935000)
libpsl.so.5 => /usr/lib/x86_64-linux-gnu/libpsl.so.5 (0x00007f91eb727000)
libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f91eb4bd000)
libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f91eb045000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f91eadfa000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f91eaba8000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f91ea99a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f91ea77d000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f91ea557000)
libunistring.so.2 => /usr/lib/x86_64-linux-gnu/libunistring.so.2 (0x00007f91ea1d9000)
libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f91e9e74000)
libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f91e9c40000)
libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f91e9a0a000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f91e9789000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f91e94b3000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f91e9281000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f91e907d000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f91e8e72000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f91e8c57000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f91e8a3c000)
libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f91e87fb000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f91e84cc000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f91e82b9000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f91e80b5000)
libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f91e7eac000)
libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f91e7c1f000)
libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f91e797d000)
libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f91e7747000)
libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f91e7531000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f91e7329000)
libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f91e7100000)
libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f91e6ef1000)
libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f91e6ca7000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f91e699e000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f91e6766000)

所有未建立的库(如libFoundation.so)均被列出两次。一旦找不到,然后找到。

为什么?这可能是为什么它不执行的问题吗?

1 个答案:

答案 0 :(得分:0)

关于Fedora的类似问题(32)。假设这可能与通过snap安装swift都有关:

sudo snap install swift-lang --edge --devmode

dnf

sudo dnf install swift-lang