With newly built swiftc, I found out the program was still (if I understand correctly) linking against system's stdlib, instead of custom built one (i.e. build/Ninja-RelWithDebInfoAssert+stdlib-DebugAssert/swift-macosx-x86_64/lib/swift/macosx/libswiftCore.dylib):
IMO it indicates that testprog is linking against system default stdlib. and I have tried several ways:
Change testprog's install name for libswiftCore.
Force dynamic link all libswift*.dylib.
but either of them failed.
Since the functions I'm interested in are located in libswiftCore, for exmaple Collection.map(), how can I correctly link against to the custom built stdlib? Could anyone give some clues, would be much appreciated!
You can set the DYLD_LIBRARY_PATH environment variable while launching testprog to point at your build directory containing your locally-built runtime libraries, and then dyld should favor those over the ones in the OS.
There is a compiler flag to force this on macOS, -toolchain-stdlib-rpath, which the source code doc says exists for scenarios like yours. Linux has that flag turned on by default, since it usually doesn't ship with a Swift stdlib in the OS.
@Finagolfin Thanks for the reply! The option -toolchain-stdlib-rpath make effects but somewhat weird, I have tried to compile with -toolchain-stdlib-rpath, results in two RPATH settings, one is of toolchain the other of system:
The macOS's DYLD_LIBRARY_PATH seems working as expected for normal C/C++ program's dynamic linking. But here it doesn't affect Swift's dynamic linkage, a little confused, is there anything I've missed for swiftc?
swiftc -g testprog -L <path to directory containing your library>
You can use as many -L parameters as you need. The -L parameter adds the directory to front of user linker search paths, ahead of system paths, DYLD_... paths, etc.
Hi, I'm facing a similar issue and thanks to @Joe_Groff suggestion (setting DYLD_LIBRARY_PATH) I was able to run my test app from terminal. However, I'm trying to override DYLD_LIBRARY_PATH on Xcode, but for some reason it is not getting the custom path.
I tried setting -toolchain-stdlib-rpath as @Finagolfin suggested, but nothing worked for me.
In my example, I added an extension from String.swift with the property "debugMessage". I've created a custom toolchain and compilation works well. The problem is the execution: