35

I created a brand new project in Xcode 11 (an iOS single-view project with SwiftUI) and enable Mac as a target device. Without doing anything else, I try to build, and I get this error:

ld: warning: directory not found for option '-L/Applications/Xcode'
ld: warning: directory not found for option '-L11.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/uikitformac'
ld: warning: directory not found for option '-L/Applications/Xcode'
ld: warning: directory not found for option '-L11.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/uikitformac'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
Undefined symbols for architecture x86_64:
  "__swift_FORCE_LOAD_$_swiftUIKit", referenced from:
      __swift_FORCE_LOAD_$_swiftUIKit_$_MyProject in AppDelegate.o
      __swift_FORCE_LOAD_$_swiftUIKit_$_MyProject in SceneDelegate.o
      __swift_FORCE_LOAD_$_swiftUIKit_$_MyProject in ContentView.o
     (maybe you meant: __swift_FORCE_LOAD_$_swiftUIKit_$_MyProject)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Environment

  • macOS 10.15 Catalina Beta (19A487l)
  • Xcode 11.0 beta 2 (11M337n)
    • Swift 5 mode
Ky -
  • 30,724
  • 51
  • 192
  • 308

8 Answers8

129

Update: This works for XCode Version 13.0 (13A233), too.

For XCode Version 12.0.1 (12A7300),

I just added libswiftWebKit.tbd to

Link Binary with Libraries (from project, Build Phases)

and the build was successful.

See image below: enter image description here

Florent
  • 1,755
  • 1
  • 14
  • 13
  • 2
    Works for me with Xcode 13, thanks – Serhii Onishchenko Sep 23 '21 at 19:08
  • 4
    After adding `libSwiftWebKit.tbd` to `Link Binary with Libraries`, you can immediately remove it. It should add `$(SDKROOT)/usr/lib/swift` to `Library Search Paths` in `Build Settings`. This way it also won't break backwards compatibility with Xcode 11. – Dror Bar Sep 28 '21 at 12:54
  • 1
    This also solved an issue I had with building my Expo bare workflow React Native project. Definitely worth noting if you're having issues building React Native on the newer versions of XCode. – Falgantil Oct 15 '21 at 10:03
  • 1
    This worked for me but broke builds of iOS13 and lower. Setting the Status to Optional allowed my iOS13 and lower build to work. [link](https://github.com/facebook/react-native/issues/30287#issuecomment-940638389) to Github thread. – makenova Dec 17 '21 at 16:41
  • thanks, this solve for my M1 and Xcode 13, build is working – Syed Amir Ali Jan 25 '22 at 09:38
  • I added this but app is not working on IOS 12.5.5 version – Harleen Kaur Arora Jul 04 '22 at 06:14
9

Go to Xcode, in the project name, right click and click on “New file…” Select Swift File and click on Next Select the project target and Finish In the next screen select “Create bridging Header” - Make sure to bridge.

Keep the swift file there for future in order to run the simulator.

PavelPark
  • 91
  • 1
  • 2
  • Thank you for making an account just to answer my question! Here on Stack Overflow, we like to have each answer be a separate way to solve the question. I think your answer is the same as [Anh's](https://stackoverflow.com/a/64025431/3939277), but you've provide more detailed steps – Ky - Oct 03 '20 at 21:53
  • This was the solution that worked for me, but only after I created a bridging header for the test target as well. I didn't see any indication of this and only managed to get to it by trial and error. – Jesús Cruz Sep 23 '21 at 10:59
8

Create an Empty Swift file using Xcode, such as named test.swift, and try to run again

Anhdevit
  • 1,926
  • 2
  • 16
  • 29
  • 1
    For my particular question, this solution is not applicable because it was already a swift project with a bridging header. This answer might help others with similar error messages, though. – Ky - Oct 15 '20 at 18:28
  • 2
    My error was `Undefined symbol: __swift_FORCE_LOAD_$_swiftDataDetection` with build fail, after updating Xcode to 13. And this solution worked. thanks – Arosha Oct 28 '21 at 01:19
3

For me, I used to encounter link error with swift library with Xcode 12, I resolved it by add "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)" and "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" into the "Library Search Paths" of "Build Settings"

Jimmy liu
  • 1,587
  • 1
  • 13
  • 14
2

As hinted by the warnings saying directory not found, it seems Xcode doesn't like having a space in its bundle's file name.

I renamed it from Xcode 11.0-Beta.2.app to Xcode-11.0-Beta.2.app and now it builds just fine.

Ky -
  • 30,724
  • 51
  • 192
  • 308
2

I had this error when I accidentally imported XCTest to the app target. Didn't notice it till I checked git diff. If you run into this issue make sure you didn't export inappropriate stuff too

ramzesenok
  • 5,469
  • 4
  • 30
  • 41
1

I had to reinstall Xcode completely, because of missing swift folder in "$(TOOLCHAIN_DIR)/usr/lib"

0

Remove

"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" from "Library Search Paths” of Build Settings

MAhipal Singh
  • 4,745
  • 1
  • 42
  • 57