Linker Error while testing: Undefined symbols for architecture x86_64 - ios

I am working to support iOS 11 and XCode 9. When I try to execute the test suite, I receive a Linker Error:
Undefined symbols for architecture x86_64
"ConstantName", reference from: - [FileATest testMethod] in FileATest.o
In FileA.h
OBJC_EXTERN NSString *const ConstantName
In FileA.m
NSString *const ConstantName = #"ConstantValue"
In FileATest.m I use the constant and have the import
#import "FileA.h"
Using a static constant in the header file seems to work, but I read that it is not the proper way to declare a constant.
It was working fine with XCode 8 and previous versions, but for XCode 9 Beta 6 it doesn't. Has someone had this problem? How may I fix it?

I had the same issue when running unit tests and the solution for me was to go to the App Target > Build Settings > Dead Code Stripping and set it to NO.
Hope this helps.

Related

Clang Error "duplicate symbols for architecture x86_64"

This error is listed a lot over stack and the common fixes don't seem to work for me. I am getting the error: "duplicate symbols for architecture x86_64" when compiling an Obj-C MacOS Xcode App. Xcode 11.5 and MacOS Catalina 10.15.5. It is saying there are 15 duplicate symbols, with one of the 15 errors looking like:
duplicate symbol '_visual10Window' in:
/Users/tempuser/Library/Developer/Xcode/DerivedData/test-cdicjztmkktfomehwaphnzhbozgh/Build/Intermediates.noindex/test.build/Debug/test.build/Objects-normal/x86_64/Test.o
/Users/tempuser/Library/Developer/Xcode/DerivedData/test-cdicjztmkktfomehwaphnzhbozgh/Build/Intermediates.noindex/test.build/Debug/test.build/Objects-normal/x86_64/MainView.o
My MainView.h and MainView.mm do not contain any definition for visual10Window.
My Test.h has (removing this give a use of undeclared identifier error).
#class Visual10;
Visual10 *visual10Window;
and Test.mm includes
#import "Visual10.h"
and I'm calling a xib from a menu item in Test.mm
- (void)Visual10Menu:(id)sender {
if (!visual10Window) {
visual10Window = [[Visual10 alloc] initWithWindowNibName:#"Visual10"]; }
[visual10Window showWindow:self]; }
I have tried the common suggestions including:
Install and reinstall pods (this project doesn't use pods)
Checked for wrong imports like import ".m" instead of ".h"
Remove -all_load from Other Linker Flags
Build Settings / No Common Blocks set to NO
Checked for duplicate files Build Phases / Compile Sources (None)
Tried adding and removing -ObjC from Other linker flag
Tried Build Settings / Enable Testability set to NO
Tried clearing derived data
None of these work and still get duplicate symbol errors.

iOS 11 - Xcode 9.0 Beta 3 error: Use of undeclared identifier 'vabs_s8'

Xcode gives me this weird error: Use of undeclared identifier 'vabs_s8'
File path: /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/usr/include/simd/common.h
This file is included by GameKit framework:
GameKit.h => simd.h => vector.h => common.h
Any suggestions how to fix this?
This error is to do with the architecture your targeting. A simple workaround is to place these at the top of common.h file.
#undef arm64
#undef arm
As you've noticed,gamekit includes simd/common.h in which ‘vabs_s8()’ function is undeclared.
Naturally, simd/common.h includes simd/base.h -> and -> simd/base.h includes arm_neon.h if ARM_NEON is defined. In arm_neon.h we have the declaration of ‘vabs_s8()’ function.
So if vabs_s8 is undeclared means the header is not included which means __ARM_NEON__ is not defined.
__ARM_NEON__ is enabled by default if you target armv7/arm64, so this means there might be something wrong with your project settings.
Solution: One of our programmers found out that adding "-mfpu=neon" in Other C Flags fixes this issue.

Drag and Drop into a `UICollectionView` placeholder in iOS 11 Beta 4

The API for dragging and dropping into a UICollectionView changed in iOS 11 Beta 4. In beta 1-3, the code looked like:
let placeholderContext = coordinator.drop(
item.dragItem,
toPlaceholderInsertedAt: indexPath,
withReuseIdentifier: "reuseID",
cellUpdateHandler: { _ in }
)
In beta 4, the introduced UICollectionViewDropPlaceholder. My code is
let placeholder = UICollectionViewDropPlaceholder(
insertionIndexPath: indexPath,
reuseIdentifier: "reuseID"
)
let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)
I am getting this compile error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_UICollectionViewDropPlaceholder", referenced from:
objc-class-ref in StickerLibraryViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
note: symbol(s) not found for architecture arm64
error: linker command failed with exit code 1 (use -v to see invocation)
Other than not using a placeholder until beta 5, anyone have any ideas of how to get this working in beta 4?
Thanks!
Until this is fixed in Beta 5, I ended up solving this issue by dropping down into the Objective-C runtime.
In the Obj-C header…
NS_ASSUME_NONNULL_BEGIN
#interface RKNFactory : NSObject
- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier;
#end
NS_ASSUME_NONNULL_END
In the implementation…
#import ObjectiveC.runtime;
#implementation RKNFactory
- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier {
SEL initSelector = NSSelectorFromString(#"initWithInsertionIndexPath:reuseIdentifier:");
Class placeholderClass = NSClassFromString(#"UICollectionViewDropPlaceholder");
return [[placeholderClass alloc] performSelector:initSelector withObject:indexPath withObject:reuseIdentifier];
}
#end
And then from the Swift code…
return RKNFactory().placeholder(for: indexPath, resuseIdentifier: reuseIdentifier)
I had a similar problem with local authentication not compiling on on the simulator architecture when it was in beta.
Does it compile if you remove arm64 from valid architectures in build settings (or turn off “build all architectures”)?
If they compiled this symbol for simulator, but left it out for arm64, the only solution might be to prevent it from compiling on arm64 and test it only on the simulator for now.
You can also wrap the code temporarily in a “#if block” that prevents the compiler from looking at it when building arm64.
Finally, if you’re building for any versions of iOS under iOS 11, be sure to try turning those off for now, in case they forgot to mark API availability (which might have let the compiler provide a more helpful message).

Linker error when implementing NSObject protocol while using enums?

Here is a distilled version of the code I am having trouble with in Swift:
enum E {
case C
}
class Test: NSObject {
var v: E = .C
}
When I attempt to build, I get the following error:
Undefined symbols for architecture x86_64:
"__TWvdvC8TestTest4Test1vOS_1E", referenced from:
__TFC8TestTest4Testm1vOS_1E in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
To reproduce this, simply make a new Swift project and paste the above code right into "AppDelegate.swift". Alternatively, make a new file and stick it in there instead!
Am I missing something obvious or is this yet another Swift bug? I did try deleting all derived data and other forms of voodoo magic.
Thanks for the help!
It seems like the compiler removes the enum if there is only one case?
I can reproduce your issue, it disappears when I add a second case :
enum E {
case C,D
}
class Test: NSObject {
var v : E = .C
}
I noticed a couple things when trying this:
In the current non-beta version of Xcode, I see the error you're referring to (almost certainly a Swift bug). However, if I add an extra value to the enum (case C,D), it compiles just fine
I couldn't reproduce the crash in the latest Xcode beta (Version 6.3 (6D520o)), which leads me to believe that the bug has been fixed in Swift 1.2

UIColor Category Linker Errors

Earlier today I tried to add Unit tests to my xcode project for a static framework that I am creating. After adding the Unit Tests target to my project, I was able to successfully run the unit tests template and have the tests catch the default assertion. Then, after importing the file that I wanted to test into my new SenTestCase subclass, I tried to run the test but my UIColor category failed building with the test due to linker errors. The text of the linker errors is as follows:
Undefined symbols for architecture i386:
"_CGColorGetComponents", referenced from:
-[UIColor(ColorExtension) hexValue] in StaticFramework(StaticFramework)
"_CGColorGetNumberOfComponents", referenced from:
-[UIColor(ColorExtension) hexValue] in StaticFramework(StaticFramework)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Next, I found where these two references were in my project. Both live in my category under the following function:
- (NSString *)hexValue
{
UIColor *color = self;
const size_t totalComponents = CGColorGetNumberOfComponents(color.CGColor);
const CGFloat * components = CGColorGetComponents(color.CGColor);
return [NSString stringWithFormat:#"#%02X%02X%02X",
(int)(255 * components[MIN(0,totalComponents-2)]),
(int)(255 * components[MIN(1,totalComponents-2)]),
(int)(255 * components[MIN(2,totalComponents-2)])];
}
If I remember correctly, both of these are part of the NSColor class. With a little more inspection, I also noticed that in my Unit Test's framework's folder, both UIKit.framework & Foundation.framework are red. I have tried reimporting them and building but this does not fix that issue either.
Interestingly enough, my static framework will still build and run fine as long as the associated Test is not also run. And when I comment this function out (and every time I use it), the Unit Test builds without issues. Would I be correct in my assumption that the missing UIKit.framework & Foundation.framework could be causing the linker not finding the NSColor properties? Does anyone have any additional suggestions that could explain why these properties are causing these issues or what I could do to fix them?
Any help would be greatly appreciated. Thanks for the assistance.
The linker error indicates that you are using CoreGraphics functions but you are not linking the CoreGraphics framework.
Update your project/target so you link the CoreGraphics.framework and the linker issues will be resolved.

Resources