Swiftc and swift failed to execute after compiling the swift compiler with --release-debuginfo

Hi developers,

I've successfully built the swift compiler using Ninja by following the instructions listed in the Getting Started document. However, when I tried to execute swiftc and swift respectively in the build directory, I got the following errors:

Command I used to invoke swiftc:

<my build directory>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc test.swift -o test

The output I got:

ld: library not found for -lobjc
:0: error: link command failed with exit code 1 (use -v to see invocation)

and after I added the -v option, I got the following output

Swift version 5.4-dev (LLVM 1044437905e95a4, Swift d622bdca3a5d1fd)
Target: x86_64-apple-darwin20.3.0
<my build direcory>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file test.swift -target x86_64-apple-darwin20.3.0 -enable-objc-interop -module-name test -o /var/folders/zx/1t__6cgd5rdblpb72g6fbz2h0000gn/T/test-e50629.o
/usr/bin/ld /var/folders/zx/1t__6cgd5rdblpb72g6fbz2h0000gn/T/test-e50629.o <my build directory>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/clang/lib/darwin/libclang_rt.osx.a -lobjc -lSystem -arch x86_64 -L <my build direcotry>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx -platform_version macos 11.0.0 0.0.0 -no_objc_category_merging -o test
ld: library not found for -lobjc
:0: error: link command failed with exit code 1 (use -v to see invocation)

Command I used to invoke swift:
<my build directory>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift

and I got the following output:

<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (Swift.org - Contributing) and include the project
:0: note: Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead.
Please submit a bug report (Swift.org - Contributing) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: <my build directory>/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -repl -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -color-diagnostics -target-sdk-version 11.1 -module-name REPL

  1. Swift version 5.4-dev (LLVM 1044437905e95a4, Swift d622bdca3a5d1fd)
    Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
    0 swift-frontend 0x0000000105680497 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
    1 swift-frontend 0x000000010567f565 llvm::sys::RunSignalHandlers() + 85
    2 swift-frontend 0x0000000105680ac6 SignalHandler(int) + 262
    3 libsystem_platform.dylib 0x00007fff2053ed7d _sigtramp + 29
    4 libsystem_platform.dylib 0x000000011af946c0 _sigtramp + 18446603344721303904
    5 libsystem_c.dylib 0x00007fff2044d720 abort + 120
    6 swift-frontend 0x00000001009a2305 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_2::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, bool) + 725
    7 swift-frontend 0x00000001055d14db llvm::report_fatal_error(llvm::Twine const&, bool) + 267
    8 swift-frontend 0x00000001055d13cb llvm::report_fatal_error(char const*, bool) + 43
    9 swift-frontend 0x00000001009a1e8d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 10941
    10 swift-frontend 0x000000010093ade7 main + 519
    11 libdyld.dylib 0x00007fff20515621 start + 1
    zsh: abort

My development environment:
Xcode 12.4
Python 3.8.2
macOS 11.2
cmake 3.19.4
ninja 1.10.2

All commands were invoked with the working directory being the directory that contains the swift source code I want to run those two programs on

Could you help me with that?

Thank you so much

This error is an indirect result of the compiler not finding your SDK. Specifying it with -sdk should work (you can use xcrun --show-sdk-path to find the default path)

The REPL error is being reported because LLDB (which powers it) can’t be found. The easiest way to build and test it is to include —lldb in your build-script invocation, and then run it directly from the build folder using /path/to/lldb —repl.

Hope this helps!

Thank you! It works! By the way, I wonder how I can make it automatically detect the path to the SDK without manually specifying it with -sdk?

When using ‘swiftc’, you can also specify the sdk using the SDKROOT environment variable, but it will never be set completely automatically. When using ‘swift’, it will use xcrun to find the sdk on macOS if you don’t specify one since that’s intended to be more of an interactive tool

Got it, thanks!

For this, do I need to do a clean build with --lldb option enabled?

If you add —lldb to your original invocation I think it will probably work without a clean build, but I could be wrong

Thanks. I tried but it said the --lldb option is unknown to swift

Oh sorry, I meant you’ll need to pass it to build-script, so probably something like this:
utils/build-script --skip-build-benchmarks
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)"
--sccache --release-debuginfo —lldb

When you don’t plan on using/contributing to the REPL I usually don’t recommend building it though because it’s a pretty large project.

Got it, thanks Owen!

Terms of Service

Privacy Policy

Cookie Policy