Code doesn't compile in unit tests target (XCode) - xcode

I have a problem with my unit tests in XCode. I have an active target which directly depends on a UnitTests target. I have generated some code with ProtocolBuffers library and I have added these classes together with ProtocolBuffers project to my project. Everything compiles well in the active target, however in the UnitTests target I'm getting the following error:
Undefined symbols for architecture armv6:
"_OBJC_CLASS_$_CRequestMessage", referenced from:
objc-class-ref in CConnection.o
ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status
I had noticed that the generated m file is not added to the UnitTests target so I added this file to the target. Now I'm getting over a thousand errors, including:
(...) ../ProtoBuff/Classes/CodedInputStream.h:27: error: cannot find interface declaration for 'NSObject', superclass of 'PBCodedInputStream'
NSObject is not visible?
Of course before adding the generated code everything had worked and compiled well.
Any ideas how to deal with this?
Thanks!

Did you add "ProtocolBuffers.h" to your target?

Related

xcode 10.1 Undefined symbols for architecture arm64

I already gone so many SO threads with similar issue but none of them seems to resolve my error.
In our project we have multiple "TARGETS". Only one of the target - the very first target created ever - is archiving properly. When I try to archive other target we encounter this error
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_DynamicEventData", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in DataReader.o
"_OBJC_CLASS_$_DynamicDataService", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DynamicDataConfig", referenced from:
objc-class-ref in DataManager.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I did compare the Build Setting of the working target to the other targets but all of them are equal. I checked the header files and they exists in our project directory. I tried to manually add the header files' path to Header Search Paths but same result still getting the error.
Any idea? I really need to resolve this to export an ipa file.
Thanks!
I scan manually check the Build Phases > Link Binary With Libraries of the working target vs the defected targets. I found a one framework/library that was only added to the working target the said framework isn't manage by pod that may explain why the other target doesn't have it. I think it was added manually in the project.
I add the said framework to all targets and now I can build without the said error.
Thanks!
I encountered the same problem and the solution I found is so simple (man....).
Search in the project for the classes that are mentioned in the error.
Go to the "File Inspector" and simply check V for the rest of the targets in the "Targets Membership".
That's it! It took me Two Hours (wasted time) to find out.
Hope my solution will save time for anyone with similar problem.

What does this mean: Undefined symbols for architecture x86_64 "_main"

I keep getting errors upon building my application on Xcode:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
None of my code is erroring and the errors are weird errors and anything I do does not resolve it. I don't think the code is relevant to the issues because it isn't referenced in the error.
This is a screenshot of the error.
The linker has not been able to find any file in the linking process with the main swift entry point. This can be due to the file not existing at all in your project, or that it exists but has not been included in the compile or link build phases.
In Swift, the main swift entry point is defined in a main.swift module, or (for iOS) in the AppDelegate.swift file there needs to be a #UIApplicationMain declaration. I don't see a Compile main.swift in your log, perhaps its missing or not included in the build phases?
Just in case, check if your AppDelegate app target is selected on the File Inspector.
( Select AppDeletage > Show the Utility > Show the file Inspector > under Target Membership, select your target.)
It happened to me after renaming an existing file.
Some time remove the reference of AppDelegate.swift from the project and add AppDelegate.swift again in project will work.

Undefined symbols in SenTestingKit

Just turned on unit testing on an existing project, follow all the instruction here, here will no luck.
Any hints? There are tests that work, but I was testing with a category class instead of a totally custom class.
I should also mentioned that I am using CocoPods which seems to compile fine in the test target. Oh, and I am using xcode 4.6
Here is the relevant error msg:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_UIHelpers", referenced from:
objc-class-ref in EventHashTest.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What's happening here is that your implementation (.m) for UIHelper can't be found by the UnitTest. You need to make sure your UIHelper.m is part of your app or your unit test target. See how the UIHelper.m is indicated as having target membership by the text box in the ride pane:
And, the unit test target is able to find this implementation b/c this target depends on the app target. See in the middle pane where the app is listed as a target dependency:

getting linker error even after linking the core data.framework to my project target file

I have linked the target file of my project to the coredata.framework in the Build Phases.
But still I am getting 3 linker errors like below:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CoreDataTableViewController", referenced from:
_OBJC_CLASS_$_RolesTableViewController in RolesTableViewController.o
"_OBJC_METACLASS_$_CoreDataTableViewController", referenced from:
_OBJC_METACLASS_$_RolesTableViewController in RolesTableViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting this problem in 2 coredata examples i was following from the tutorials. I tried to find if i missed a step. I think I am doing some small fundamental error...
Please help, what it could be...
I'm sure this is solved now, but I had the same problem. When you copy the files to your project you need to ensure you put a check next to your project under "Add to targets".

How to link to another library in Xcode?

I created a command line application. Then I realized it would be handy to be able to use code in other projects, so I added a new target - a cocoa library.
It seems to compile and a .a file is generated.
Now in another project I want to use this library. So first I added the first project to this new project as a reference.
In build settings I set "Always search user paths" to YES, then keyed in the path to the above project in user header paths.
In build phases, "Link Binary with libraries" , I added the .a file.
Now in my new project code sense seems to work. But when I try to build, I get an error : ndefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RIImageSplitter", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What did I do wrong? :S I am a beginner.
Didn't add file to compile sources of target. =S
Check this:
Did you drag the static library to your project navigator?
Did you add in Target/Build Phases/ Target Dependencies?
Did you add the Header Search Path for the headers of the static library?
Good Luck!

Resources