gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:32:07 26 4
gpt4 key购买 nike

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

架构 i386 的 20 个重复符号

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

问题是我已经检查了我的项目中是否存在任何重复的类文件、图片、音频文件(没有)。我已将所有 .m 文件导入到build phases-> compile sources。在link with binary libraries中也导入了正确的框架,并检查copy bundle resources中的图片、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)

最佳答案

这是非常非常基础的初学者内容,向我表明您不了解 C 系列语言的“头文件”和“实现文件”之间的区别。

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

当然,您确实知道要避免这种“全局变量困惑”,而且是糟糕的编程习惯吗?您应该考虑将全局变量排除在代码之外,并尽可能将变量的范围限制在单个实现模块中。

在 .h 文件中:

extern UIImage * myImage;

在 .m 文件中:

UIImage *myImage;

请去阅读有关 extern 关键字含义的书籍。另外,我怀疑您可能打算这样做:

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

上面是一个实例变量(属于类的每个实例)。如果您需要对一些东西进行分组并将其放入对象中而不是使其成为全局变量,这很常见。

关于xcode - 即使在将 .m 类文件链接到 Xcode 中的构建阶段后,Apple Mach-O 链接器仍会出现重复符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16144666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com