55

Recently I downloaded Xcode 9 and created one sample iPhone app but the app is not able to build as it shows the following error:

ld: entry point (_main) undefined. for architecture x86_64

I searched on net about same and tried few ways like deleting derived data, restarting Xcode but still not fix the problem.

Anybody has faced similar issue?

JimHawkins
  • 4,843
  • 8
  • 35
  • 55
Meluha
  • 1,476
  • 1
  • 9
  • 12

13 Answers13

92

Adding @main fixed the issue.

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
...
}

@UIApplicationMain was prior to Swift 5.3.

Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
Norman
  • 3,020
  • 22
  • 21
77

Found out that "AppDelegate" wasn't part of "target" membership.

Meluha
  • 1,476
  • 1
  • 9
  • 12
  • 4
    can you please elaborate it more. I could not get what you identified. – user6159419 Jul 09 '18 at 13:48
  • 8
    Jesus. Can't believe this was the issue – magneticrob May 22 '19 at 15:02
  • 4
    @user6159419 He means that in XCode, click on your project in the project navigator, then go to Build Phases, then go to Compile Sources and make sure that AppDelegate is included among the Compile Sources – Alan S Aug 21 '19 at 09:04
  • 1
    click on AppDelegate->Go to File Inspector->Check in target membership – Mak K Sep 21 '20 at 17:24
  • Add The AppDelegate.swift in the Compile Source by clicking on plus icon locate In your Target project – Murphy Feb 22 '21 at 09:34
  • 1
    Thanks, I didn't expect it could be as simple as that, the proj file is messed up during rebase in my case and newly added MyApplication.swift is not added to the target. – infinity_coding7 Nov 28 '22 at 20:34
38

I've been faced with same problem. here is how i fixed it: Select your Project then go to Build Setting -> Search Mach-O Type Change to -> Bundle . hope it will help!

Janine
  • 581
  • 5
  • 5
12

In my case, I missed @UIApplicationMain in AppDelegate.swift. Adding it right before class AppDelegate, my app started building again

AAEM
  • 1,837
  • 2
  • 18
  • 26
yuuuuuuuuuki
  • 151
  • 1
  • 5
  • Due to old laptop (therefore stuck on Catalina), I am trying to back-port a Big Sur (etc. Xcode and Macbook Pro) to Catalina on Macbook Pro (mid 2012) which sits precariously between the two development platforms. This was the last build (linker) issue. – mobibob Sep 07 '21 at 21:22
5
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  ...
}

Swift 5

Make sure you have @main at the beginning of your appDelegate class.

Charles
  • 105
  • 1
  • 9
3

Please Open your AppDelegate.swift class and check if @UIApplicationMain is written or not. If not then add this line of code in this class below the import UIKit "@UIApplicationMain".

Same like this: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { ... }

HafizAnser
  • 553
  • 6
  • 10
3

Make sure "AppDelegate" is part of "target" membership.

Click AppDelegate -> Attribute inspector -> Check Target membership

enter image description here

Rahul Panzade
  • 1,302
  • 15
  • 12
3

Add @UIApplicationMain to fix the issue. As well as what it does internally you can do the same by your own. In that case, you don't need to add @UIApplicationMain. Simply create one swift file name it main and put the below code inside it. It will work as expected.

import UIKit

UIApplicationMain(CommandLine.argc, 
    UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)), nil, NSStringFromClass(AppDelegate.self))
Pinguin895
  • 999
  • 2
  • 11
  • 28
Tapash Mollick
  • 135
  • 1
  • 11
2

For Framework (Dynamic Library)

If you're facing this error while building a framework, then select the Dynamic Library Under the Build Settings > Mach-O Type.

Tested on the Xcode Version 11.6 (11E708)

Best.

MGY
  • 7,245
  • 5
  • 41
  • 74
2

in my case @main was commented .

your AppDelegate should be like this :

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    //
}
Adnan Abdollah Zaki
  • 4,328
  • 6
  • 52
  • 58
2

In my case I accendtly removed my appDelegate file :)

Mehrdad
  • 1,050
  • 1
  • 16
  • 27
0

just add this code in appDelegate

var window: UIWindow?
0

In my case none of these answers helped.
The problem occurred, when archiving the release build.

Preview Assets.xcassets

I moved Preview Assets.xcassets to the root folder of the project, so, you have to move it back to the separate folder

  1. In your root folder App/ create a folder named Preview Content
  2. Drag & drop Preview Assets.xcassets to Preview Content
  3. Go to your target settings
  4. Select Build Settings -> All and Combined
  5. Search for Development Assets
  6. Change the path to "App/Preview Content"

Tested on XCode 14.2 (14C18)

I'm not able no upload photos yet, sadly, but I hope links to them is enough!

levochkaa
  • 1
  • 1