[英]Xcode: I just got an Apple Mach-O Linker (Id) Error and don't know why
I'm new to iOS Development, I'm using the latest version of Xcode and just got an error that said Apple Mach-O Linker (Id) Error exit code 1 and I haven't got a clue why. 我是iOS开发的新手,我使用的是最新版本的Xcode,但遇到一个错误,该错误表示Apple Mach-O Linker(Id)错误退出代码1,我不知道为什么。 I think this is relevant but I'm not sure what it means:
我认为这是相关的,但是我不确定这意味着什么:
ld: duplicate symbol _OBJC_CLASS_$_Timing1ViewController in /Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/Objects-normal/i386/Mediumhb.o and /Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/Objects-normal/i386/Timing1ViewController.o for architecture i386
ld:/Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/中的重复符号_OBJC_CLASS _ $ _ Timing1ViewController。和/Users/tomkenning/Library/Developer/Xcode/DerivedData/EggTimer-ciznfdheqrtybuavrtbbcxfywyyw/Build/Intermediates/EggTimer.build/Debug-iphonesimulator/EggTimer.build/Objects-normal/i386/Timing1ViewController.o
All I've done recently is initialise and set some integer values in a .m file and then link to them from .h file from another ViewController, using #import "suchandsuch.m", there's been no errors in the code, but is that not allowed? 我最近所做的就是初始化并在.m文件中设置一些整数值,然后使用#import“ suchandsuch.m”从另一个ViewController从.h文件链接到它们,但是代码中没有错误,但是那不允许吗?
Thanks in advance for any help you can offer! 在此先感谢您提供的任何帮助!
Don't do this: 不要这样做:
#import "suchandsuch.m"
Do this: 做这个:
#import "suchandsuch.h"
You are probably compiling suchandsuch.m
, which defines the class Timing1ViewController
, normally (by including suchandsuch.m
in your target's list of files to build). suchandsuch.m
,您可能正在编译suchandsuch.m
,该类定义了Timing1ViewController
类(通过在要构建的目标文件列表中包括suchandsuch.m
)。 Then your #import "suchandsuch.m"
causes that same code to be inserted into a different source file, which is compiled as well. 然后,您的
#import "suchandsuch.m"
相同的代码插入到另一个已编译的源文件中。 The result: two different source files try to define Timing1ViewController
. 结果:两个不同的源文件尝试定义
Timing1ViewController
。
To do your constants the right way -- by declaring them extern
in suchandsuch.h
and defining them in suchandsuch.m
-- see this answer . 要以正确的方式处理常量(通过在
suchandsuch.h
声明它们为extern
在suchandsuch.h
定义它们), suchandsuch.m
见此答案 。
You probably have two Timing1ViewController
classes with the same name. 您可能有两个具有相同名称的
Timing1ViewController
类。 If you don't try to Product -> Clean and build again. 如果您不尝试使用产品->清洁并重新构建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.