更新时间:2022-05-11 01:39:17
macOS ld
将库依赖项的路径构建为二进制文件.加载libSwiftHelloWorld.dylib
的加载程序仅在libSwiftCode.dylib
在当前目录中时才能找到它.在Java中加载依赖项无效,因为对于加载器来说,它是一个不同的库.
macOS ld
builds a library dependency's path into the binary. The loader loading libSwiftHelloWorld.dylib
will only find libSwiftCode.dylib
if the latter is in the current directory. Loading the dependency in Java doesn't work because for the loader it's a different library.
您可以使用-install_name
参数(即swiftc ... -Xlinker -install_name -Xlinker <your path>
)更改libSwiftCode.dylib
的内置路径.如果之后重建libSwiftHelloWorld.dylib
,它将引用您给出的路径.
You can change the built-in path for libSwiftCode.dylib
with the -install_name
argument (i.e. swiftc ... -Xlinker -install_name -Xlinker <your path>
). If you rebuild libSwiftHelloWorld.dylib
afterwards it will reference the path that you gave.