Xcode error "Duplicate Symbol" causing Apple Mach-O Linker Error - xcode

duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToMeViewController.o
duplicate symbol _showGLobalCompany in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
ld: 3 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting the error above in xcode only when I try to build in simulator (on any iOS device I can build without error). I have three classes:
1.LTGlobalResultsViewController
2.LTJumpToMeViewController
3.LTJumpToPositionViewController
All three were created in xcode but both 2 & 3 have been modified outside of xcode and then rebuilt.
The #property bool leagueTableLoaded is defined in the header for all three. it is declared as:
#property bool leagueTableLoaded;
What is it exactly that is causing this error? I have tried the following:
I have tried renaming leagueTableLoaded in different classes but this doesn't fix it.
I have tried deleting my Derived Data files manually in library/developer/xcode folder.
According to other questions I have checked if I am importing a .m file. This is not the case. Apple Mach-O Linker error ("duplicate symbol")
Any other suggestions or advice?
Thanks,
James
ADDITION: As requested please find all the extracts from my .h and .m files that reference leagueTableLoaded or any of the variants I created when trying to get round this error:
LTJumpToMeViewController.h
#property bool leagueTableLoadedMe;
LTJumpToMeViewController.m
#implementation LTJumpToMeViewController
bool leagueTableLoaded = false;
LTGlobalResultsViewController.h
#property bool globalLeagueTableLoaded;
LTGlobalResultsViewController.m
#implementation LTGlobalResultsViewController
bool leagueTableLoaded = false;
LTJumpToPositionViewController.h
#property bool leagueTableLoadedPos;
LTJumpToPositionViewController.m
#implementation LTJumpToPositionViewController
bool leagueTableLoaded = false;
I can provide more information if required!

For me a duplicate symbol error came up when I absent mindedly included a .m file instead of a .h (Why does Xcode's autosuggest even show me .m files?!)

In this end this was being caused by the leagueTableLoaded bool being defined in both LTGlobalResultsViewController.m and LTJumpToPositionViewController.m.
Removing it from one of them fixed the issue. Although I'm not sure why it was there in the first place! Hope this helps anyone else who experiences the same issue! James

Xcode error “Duplicate Symbol” causing Apple Mach-O Linker Error is caused by duplicate symbols in Project. Steps to avoid error
Go to project -> Target ->Build Phases ->Compile sources
Check for the duplicate file (implementation file)
Delete the file and add it again
Clean and run project again
This worked for me. Hope it helps

In second view controller, you mistakenly #import "First.m", check it must be first.h file so replaces this with first.h. It's working for me.

Related

Receiving a build error related to storyboard

I downloaded some Xcode projects from the Stanford University website.
But when I run them, I get the following two errors:
:-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard':-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard'
:-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard'
Here is the link to the project:
EmojiArtL12:
https://drive.google.com/drive/folders/1reg6-ZhLPIubmNO6aMDoTni-G728H0b0
I tried looking for answers on this board but couldn't find any.
Go to the 2 links in the error message, you will find the 2 files LaunchScreen.storyboard.xml -> change their file name to LaunchScreen.storyboard then it should build correctly. Hope this helps.

Creating NSManagedObject subclass leads to linker error duplicate symbols

I am trying to create a nsmanagedobject (User) by going to the Editor menu and then selecting Create NSManagedObject Subclass...this generates four files:
User+CoreDataClass.h
User+CoreDataClass.m
User+CoreDataProperties.h
User+CoreDataProperties.m
In one of my viewcontrollers I import User+CoreDataClass.h and then have this code:
//create new account entity
User* thisUser = [NSEntityDescription
insertNewObjectForEntityForName:#"User"
inManagedObjectContext:self.myController.myDataManager.managedObjectContext];
When I then build the app, I get the following clang error:
duplicate symbol _OBJC_CLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried cleaning the app and deleting my derived data but that had no results. The only way I can clear the error is to delete the generated files. Which obviously is not going to be what I need. Why is XCode creating duplicate files off this menu command? Is there a setting that I missed?
Thanks
You are manually creating NSManagedObject subclasses, that Xcode 8 already has created for you and thus get duplicated symbols.
You can find detailed information how to solve this in this answer.

clang: error: no such file or directory: ...PrecompiledHeaders..../...pch

I have a project building correctly in one machine, but i am getting the following error when i try to build it in another. Both machines have the same version of OS X and XCode, and exactly the same source files.
clang: error: no such file or directory: '/Users/Cristian/Library/Developer/Xcode/DerivedData/MadGoose-alcvoermelusildxepcbneygiwbk/Build/Intermediates/PrecompiledHeaders/MadGoose_Prefix-afbukpnsoecegqeiiuwhfersynbx/MadGoose_Prefix.pch'
I have the following files on that directory
MadGoose_Prefix.pch.data
MadGoose_Prefix.pch.pch
MadGoose_Prefix.pch.dia
MadGoose_Prefix.pch.pch.hash-criteria
Anyone knows what could it be?
Or what should i compare between the machines?
I found the problem, i had this in the Build Settings
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"${FACEBOOKSDK}\"",
);
Since we don't use Facebook on the project anymore the variable ${FACEBOOKSDK} was empty in the machine with the problem, i remove it from there and problem solved.
An extra tip for others with build problems, check the XCBuildConfigutation section of the .pbxproj directly (Everything between /* Begin XCBuildConfiguration section */ and /* End XCBuildConfiguration section */), it was easy to spot the problem there, in XCode the variables are replaced with their value unless you edit them.

OCMock link error

I'm trying to get a simple OCMock test for OSX up and running, but can't seem to get the install right. I believe I've followed the instructions, but the test build is failing at the link step.
Within fooTests.m:
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#interface fooTests : XCTestCase
#end
#implementation fooTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testOCMockPass {
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:#"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
STAssertEqualObjects(#"mocktest", returnValue, #"Should have returned the expected string.");
}
#end
But on build, I get the following warnings/errors:
fooTests.m:56:5: Implicit declaration of function 'STAssertEqualObjects' is invalid in C99
Undefined symbols for architecture x86_64:
"_STAssertEqualObjects", referenced from:
-[fooTests testOCMockPass] in fooTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've got "Link Binary with Library" linking with XCTest & OCMock in the test build phase. OCMock.framework is in the base directory, which is also in the search path for frameworks and for headers. Can anyone assist in telling me what I'm doing wrong please?
It looks as though the compiler doesn't know what STAssertEqualObjects() is (i.e. I haven't included something) and hence it doesn't know what to link with, hence the other 2 errors. I just don't know what else I need to include.
This is not an OCMock problem. You are using XCUnit (the Xcode 5 unit testing framework), but you are calling STAssertEqualObjects (from OCUnit, the Xcode 4 unit testing framework). Simply change that to XCTAssertEqualObjects.

Build failed due to error in CLEErrorDomain.h

I'm getting an odd error in line 18 of the CLErrorDomain.h under CoreLocation.framework.
The line is
extern NSString *const kCLErrorDomain;
and there is an error for "Expected identifier or "("
I haven't messed with this file at all, and it's locked anyways so it would be difficult to change. Why is this error coming up, and what can I do to get rid of it?
I've tried restarting xCode, cleaning my project and taking CoreLocation out of my project and putting it back in.
Thanks
Alright, the issue ended up not being in the CLErrorDomain.h
While looking at the error log, I noticed it was erroring out when it tried to compile the main.m... at the very top of the main.m file there was a stray "^" mark before any of the code and that was what was causing the error.

Resources