ld:入口点 (_main) 未定义。对于架构 x86_64:Xcode 9

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46648834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:20:59  来源:igfitidea点击:

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

iosswiftxcode

提问by Mahesh M

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:

最近我下载了 Xcode 9 并创建了一个示例 iPhone 应用程序,但该应用程序无法构建,因为它显示以下错误:

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

ld:入口点 (_main) 未定义。用于架构 x86_64

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

我在网上搜索了大致相同的内容,并尝试了一些方法,例如删除派生数据、重新启动 Xcode,但仍然没有解决问题。

Anybody has faced similar issue?

有人遇到过类似的问题吗?

回答by Mahesh M

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

发现“AppDelegate”不是“目标”成员的一部分。

回答by Norman

Adding @UIApplicationMain fixed the issue.

添加@UIApplicationMain 解决了该问题。

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

回答by Janine

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!

我遇到了同样的问题。这是我修复它的方法:选择您的项目,然后转到 Build Setting -> Search Mach-O Type Change to -> Bundle 。希望它会有所帮助!

回答by HafizAnser

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

请打开您的AppDelegate.swift课程并检查是否@UIApplicationMain已写入。如果没有,则在 import 下方的此类中添加这行代码UIKit "@UIApplicationMain"

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

类似这样:@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { ... }

回答by Rahul Panzade

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

确保“AppDelegate”是“目标”成员资格的一部分。

Click AppDelegate-> Attribute inspector-> Check Target membership

单击AppDelegate->属性检查器->检查目标成员资格

enter image description here

在此处输入图片说明

回答by Tapash Mollick

Add @UIApplicationMainto 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.

添加@UIApplicationMain以解决问题。除了它在内部所做的事情之外,您还可以自己做同样的事情。在这种情况下,您不需要添加@UIApplicationMain. 只需创建一个名为 main 的 swift 文件并将以下代码放入其中。它会按预期工作。

import UIKit

UIApplicationMain(CommandLine.argc, 
    UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)), nil, NSStringFromClass(AppDelegate.self))

回答by Balu Muchhal

just add this code in appDelegate

只需在 appDelegate 中添加此代码

var window: UIWindow?