Xcode 错误:“_main”,引用自:主可执行文件的隐式入口/启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28874258/
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 06:46:11  来源:igfitidea点击:

Xcode error: "_main", referenced from: implicit entry/start for main executable

iosxcodeclang

提问by John

I am getting the following error, which seems to be coming from something in the bottom to do with "_main".

我收到以下错误,这似乎来自底部与“_main”有关的东西。

Ld /Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Products/Debug-iphonesimulator/TownHall\ iPhone.app/TownHall\ iPhone normal i386
    cd "/Users/jianglin/Desktop/TownHall iPhone"
    export IPHONEOS_DEPLOYMENT_TARGET=8.1
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -L/Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Products/Debug-iphonesimulator -F/Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Products/Debug-iphonesimulator -filelist /Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Intermediates/TownHall\ iPhone.build/Debug-iphonesimulator/TownHall\ iPhone.build/Objects-normal/i386/TownHall\ iPhone.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -ObjC -lPods-AFNetworking -lPods-Masonry -lPods-SDWebImage -framework CoreGraphics -framework Foundation -framework ImageIO -framework MobileCoreServices -framework Security -framework SystemConfiguration -framework UIKit -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=8.1 -lPods -Xlinker -dependency_info -Xlinker /Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Intermediates/TownHall\ iPhone.build/Debug-iphonesimulator/TownHall\ iPhone.build/Objects-normal/i386/TownHall\ iPhone_dependency_info.dat -o /Users/jianglin/Library/Developer/Xcode/DerivedData/TownHall_iPhone-bdlgipvgaapgjhglhromfvcubbxz/Build/Products/Debug-iphonesimulator/TownHall\ iPhone.app/TownHall\ iPhone

Undefined symbols for architecture i386:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _OBJC_IVAR_$_PostTableViewCell._mainTextView, _OBJC_IVAR_$_ConfirmationViewController._mainLabel , _OBJC_IVAR_$_SignInViewController._mainLabel , _OBJC_IVAR_$_SignUpViewController._mainLabel )
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help would be much appreciated.

任何帮助将非常感激。

回答by Midhun MP

I checked your project. The issue is simple, in your project there is no main.mfile. I think you accidentally deleted that.

我检查了你的项目。问题很简单,在您的项目中没有main.m文件。我想你不小心删除了那个。

Add a new .m file to your project, name it as main

将一个新的 .m 文件添加到您的项目中,将其命名为 main

And add the following code to it:

并向其添加以下代码:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Also in your project the info.plist is also missing, so you need to add a new one.

同样在您的项目中 info.plist 也丢失了,因此您需要添加一个新的。

回答by bartosss

add @UIApplicationMain to the AppDelegate

将 @UIApplicationMain 添加到 AppDelegate

回答by Drew

My case was very similar, but slightly different. The solution was in part prompted by @Midhun-MP's answer above.

我的情况非常相似,但略有不同。解决方案的部分原因是上面@Midhun-MP 的回答。

In my instance, I had added a tvOS version of my app. After adding the new target however, main.m was not selected under Target Membership (thus, the warning messages about Undefined symbols for architecture x86_64: "_main"). Checked that off and bam -- I'm GTG.

在我的例子中,我添加了我的应用程序的 tvOS 版本。然而,在添加新目标后,在目标成员资格下没有选择 main.m(因此,出现了关于 的警告消息Undefined symbols for architecture x86_64: "_main")。检查一下,砰——我是 GTG。

Thanks @Midhun-MP.

谢谢@Midhun-MP。

main.m

主文件

回答by DBrown

I ran into this after a large upgrade, and was quite annoying to see so many answers across Github advising RN users to start a new project to remedy this issue.

我在一次大升级后遇到了这个问题,看到 Github 上有这么多答案建议 RN 用户开始一个新项目来解决这个问题,我感到非常恼火。

To start, here are the build settings I was mindful of when running into this error and the settings that should be set:

首先,这是我在遇到此错误时注意的构建设置以及应该设置的设置:

Build Phases for the App Target

应用程序目标的构建阶段

Link Binary With Libraries

将二进制文件与库链接

  • JavaScriptCore.framework
  • libPods-app_name.a
  • JavaScriptCore.framework
  • libPods-app_name.a

Compile Sources

编译源

  • AppDelegate.m
  • main.m
  • AppDelegate.m
  • 主文件

Build Settings for App Target

应用程序目标的构建设置

LinkingOTHER_LDFLAGS

链接OTHER_LDFLAGS

  • ObjC
  • lc++
  • lz
  • 对象
  • 液晶+
  • lz

If the settings look fine, but you still receive the error on build, the next step is to check the main file itself.

如果设置看起来不错,但在构建时仍然收到错误,下一步是检查主文件本身。

The Main.mfile lives in the ios/app_namefolder, and in the file itself, you will find the referenced main method. If there is an issue with this file (missing, broken), you can use the code below to recreate it:

的main.m文件住在IOS / APP_NAME文件夹,文件本身,你会发现引用的主要方法。如果此文件存在问题(丢失、损坏),您可以使用以下代码重新创建它:

main.m0.23.1 - 0.62.0 from Upgrade Helper

main.m 0.23.1 - 0.62.0 来自升级助手

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[]) {
  @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  }
}

I really hope this helps someone out in the future.

我真的希望这可以帮助将来的某个人。

回答by rejusss

If I am correct, you are using simulator to run the application. For running app on iOSSimulator requires the support of i386 architecture. The error showing like one your binary framework for linking is not supporting i386 architecture. This may be the framework 'SDWebImage' (I guess). Please try to run the application in real device not simulator, or try to download the framework which has i386 entry points.

如果我是对的,您正在使用模拟器来运行该应用程序。在 iOSSimulator 上运行应用程序需要 i386 架构的支持。错误显示您的二进制链接框架不支持 i386 架构。这可能是框架“SDWebImage”(我猜)。请尝试在真实设备而非模拟器中运行该应用程序,或尝试下载具有 i386 入口点的框架。

Another possibility is: verify the "AppDelegate" is existing in the compiled source. Hope this will help you ..

另一种可能性是:验证“AppDelegate”是否存在于编译源中。希望能帮到你 ..