即使将.m类文件链接到Xcode中的构建阶段,Apple Mach-O链接器也会出现重复符号错误

时间:2013-04-22 10:18:47

标签: xcode ios6 linker-errors objective-c++ mach-o

当我构建并运行我的项目时,我得到的唯一错误,结果是Apple Mach-O链接器错误

架构i386的20个重复符号

链接器命令失败,退出代码为1(使用-v查看调用)

问题是我检查了项目中任何重复的类文件,图片,音频文件的存在(不是任何)。我已将所有.m文件导入 构建阶段 - >编译来源 。还要在 链接中导入正确的框架,使用二进制库 ,并检查图片,xib,音频文件是否已在 复制包资源中正确导入 到目前为止一切看起来都不错。但是,当我尝试运行项目时,链接器错误仍然存​​在。谁能告诉我哪里出错?

 Ld /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Products/Debug-iphonesimulator/Taukytable.app/Taukytable normal i386
        cd "/Users/User/Desktop/Taukytable Newone"
        setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
        setenv 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/iPhoneSimulator6.1.sdk -L/Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Products/Debug-iphonesimulator -F/Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Products/Debug-iphonesimulator -filelist /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/Taukytable.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -stdlib=libc++ -mios-simulator-version-min=6.0 -framework CoreAudio -framework CoreMedia -framework CoreFoundation -framework Accelerate -framework CoreData -framework CoreVideo -framework Security -framework CoreImage -framework MessageUI -framework MobileCoreServices -framework AVFoundation -framework QuartzCore -framework SystemConfiguration -framework OpenGLES -framework AssetsLibrary -lsqlite3.0 -framework AudioToolbox -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Products/Debug-iphonesimulator/Taukytable.app/Taukytable
    duplicate symbol _SavedImage in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/MasterViewController.o
    duplicate symbol _SavedImage1 in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/MasterViewController.o
    duplicate symbol _vvvalue in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/MasterViewController.o
    duplicate symbol _lll in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/MasterViewController.o
    duplicate symbol _vvvalue in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/PAsavee.o
    duplicate symbol _SavedImage in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/PAsavee.o
    duplicate symbol _lll in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/PAsavee.o
    duplicate symbol _SavedImage1 in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/PAsavee.o
    duplicate symbol _SavedImage in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/Preview.o
    duplicate symbol _SavedImage1 in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/Preview.o
    duplicate symbol _vvvalue in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/Preview.o
    duplicate symbol _lll in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/Preview.o
    duplicate symbol _SavedImage in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/NSObject+ShareClass.o
    duplicate symbol _SavedImage1 in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/NSObject+ShareClass.o
    duplicate symbol _vvvalue in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/NSObject+ShareClass.o
    duplicate symbol _lll in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/NSObject+ShareClass.o
    duplicate symbol _vvvalue in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/CustomOverlayView.o
    duplicate symbol _SavedImage in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/CustomOverlayView.o
    duplicate symbol _SavedImage1 in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/CustomOverlayView.o
    duplicate symbol _lll in:
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/AppDelegate.o
        /Users/User/Library/Developer/Xcode/DerivedData/Taukytable-bwphmaegucpyjhfinxfulunsuhag/Build/Intermediates/Taukytable.build/Debug-iphonesimulator/Taukytable.build/Objects-normal/i386/CustomOverlayView.o
    ld: 20 duplicate symbols for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 个答案:

答案 0 :(得分:7)

这真的是非常基本的初学者的东西,它告诉我你不明白C系列语言的“头文件”和“实现文件”之间的区别。

您是否搜索过您的项目而没有注意到您在头文件中声明变量但没有extern?您甚至在链接器错误中具有全局变量的名称。是的,全局变量作为符号发送到目标文件(.o)中,如果您将标题包含在三个文件中,然后所有三个文件都声明了相同的全局变量,则会出现此错误。正是在这个问题上,发明了强大而精彩的extern关键字。

在头文件的上下文中,您不应声明实际变量,只应引用它们extern。这是您在C,C ++或Objective C编程的第一天应该学习的东西。但是,您可以将代码放入头文件中,但是,包含该头文件的每个文件都会生成一组重复的符号,从而导致链接错误,并进一步加速全球变暖的速度,并导致冰山融化。 (开玩笑说最后一部分。)

这是你的错误,这是一个头文件,但是你把它视为一个实现文件,并声明不是外部变量声明,而是实际发出全局变量到对象文件声明:

#import <Foundation/Foundation.h>

UIImage *SavedImage;
UIImage *SavedImage1;

NSString * vvvalue;
//UILabel * l2;
NSString * lll;

@interface NSObject (ShareClass)

@end
你现在告诉我。关键字extern应该在上面的代码示例中出现在哪里?真正的“将此变量发送到目标文件中”变量的声明去哪里了?在头文件中?没有。在实现文件中(视情况而定.m或.c或.cpp)。

其次,在添加extern关键字后,您现在遇到第二个问题。您可能需要在相应的.m文件中添加该全局变量的真实声明。是的,你必须在C系列语言课程中“宣布”每次全球两次。如果你真的需要系统中的所有模块能够看到那个全局变量,并且只有一个没有extern关键字,只能在你的一个.m文件中,那么曾经在头文件中作为extern。

当然,你知道要避免这种“全局变量混乱”,并且编程实践可怕吗?您应该考虑将全局变量保留在代码之外,并且尽可能将变量限制在单个实现模块中。

在.h文件中:

extern UIImage * myImage;

在.m文件中:

UIImage *myImage;

请阅读您的书籍,了解extern关键字的含义。另外,我怀疑你可能有意这样做:

@interface NSObject (ShareClass)
  UIImage * InstanceVariable;  
@end

以上是一个实例变量(属于该类的每个实例)。如果你需要将一些东西分组并将它放在一个对象中而不是使它成为一个全局变量,这是很常见的。