use_frameworks! and Model not found build error - ios

I'm working on a rather large iOS project that was originally written in Objective-C and we're now starting to add in Swift code. We are using Cocoapods to install 3rd party libraries and have included use_frameworks! in our Podfile.
In some of our Objective-C classes, we have added module imports at the top such as #import AFNetworking;
Usually, on first build of the project within Xcode, the build fails and we see module 'AFNetworking' not found but on the second build, it works fine. However, now I am trying to get Fastlane to do our builds and when using Fastlane to do the builds, we get the error 100% of the time.
In the build settings of the target:
Enable Modules (C and Objective-C) is set to Yes
Always Search User Paths is set to No
User Header Search Paths is set to $(SRCROOT)/Pods and is recursive
Any suggestions on what else I can check/try?

Have you tried checking "Other Linker Flags" to see if it has the -ObjC value in it?
You can click on your project name on your Navigator, go to Build Settings, scroll down to Linking section and double check on "Other Linker Flags" stated. If it is not there, you can manually add to it.

Today I finally found the solution to the problem. Our project is made up of multiple targets (10+) and we noticed that only the one target was failing to build. After hours of hunting around, comparing files we finally looked at the schemes and noticed that the target that wasn't working was using a scheme that had Find Implicit Dependencies unchecked. We checked this and it started to build again!
Just to note, the target would build if we built it after building one of the other targets but if you then deleted the derived data and tried to build the target then, it would fail.

Related

Swift Compiler Error: use of undeclared type with framework

I'm importing a newer version of a custom framework LCCommLibrary that creates the LCConnection class and I'm absolutely perplexed why this will build but not archive after trying multiple things.
Making sure the targets are added (4 apps, 1 Test)
Cleaning and Restarting the Project
This does builds and runs to my iOS devices, but none of the targets will Archive.
Archive usually uses the Release build configuration while building/running on the device uses the Debug build configuration, this is the hint that you have an issue there.
I would say in your case you can to go into the target's build settings, then look at Other Linker Flags, Runpath Search Paths and Library Search Paths, expand them to show the Debug and Release configurations and then ensure you have the same settings for both of them, you'll most probably find something missing in release in one of those.
Finally found the issue. The culprit was framework that was included was a debug version of the framework. This causes Archive Schemes to throw this error since the archive uses the Release as the default.
The resolution was to open the LCCommLibrary Project separately, change the Framework Target's Run Scheme to Release, Run and Build, Locate the target framework, import and embed that back into main project file, and archive as usual.

Xcode 10 beta: linker command failed with exit code 1 RPSystemBroadcastPickerView [duplicate]

An Xcode beginner's question:
It is my first experience with Xcode 4.6.3.
I am trying to write a very simple console program, that searches for paired BT devices and prints them to an NSLog.
It builds with the following error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_IOBluetoothDevice", 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)
I searched like crazy. The common problem should be a reference to a file, of which only the header files are imported and no implementation (*.m-file) is found by the linker. The IOBluetooth library is however, a standard Framework like the Foundation Framework.
What am I missing in my above statement?
I also have tried building it for a 32-bit machine (build fails again). It is clearly a linker error, however I have no idea, to what it relates, except that there is an issue with finding the implementation for IOBluetoothDevice, on both x86 and x64 architecture, while the header files are from a standard included Framework, called IOBluetooth?
For your information my main code "main.m" being:
#import <Foundation/Foundation.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h> // Note the import for bluetooth
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h> // Note the import for bluetooth
int main(int argc, const char * argv[])
{
#autoreleasepool {
IOBluetoothDevice *currentDevice;
NSArray *devices = [ IOBluetoothDevice pairedDevices];
for (id currentDevice in devices){
NSLog(#"%i : %#",[ currentDevice classOfDevice ], [ currentDevice name ]);
}
}
return 0;
}
Thanks for any help or pointers to the right direction.
It looks like you are missing including the IOBluetooth.framework in your project. You can add it by:
Clicking on your project in the upper left of the left pane (the blue icon).
In the middle pane, click on the Build Phases tab.
Under "Link Binary With Libraries", click on the plus button.
Find the IOBluetooth.framework from the list and hit Add.
This will make sure that the IOBluetooth.framework definitions are found by the linker. You can see that the framework is a member of your target by clicking on the framework in the left pane and seeing the framework's target membership in the right pane (note I've moved the framework under the Frameworks group for organization purposes):
UPD
Apple requires to use arm64 architecture. Do not use x32 libraries in your project
So the answer below is not correct anymore!
Old answer
The new Xcode 5.1 sets the architecture armv7,armv7s,and arm64 as default.
And sometimes the error "build failure “Undefined symbols for architecture x86_64”" may be caused by this. Because, some libs (not Apple's) were compiled for x32 originally and doesn't support x64.
So what you need, is to change the "Architectures" for your project target like this
NB. If you're using Cocoapods - you should do the same for "Pods" target.
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_xxx",
referenced from:
objc-class-ref in yyy.o
This generally means, you are calling "xxx" (it may be a framework or class) from the class "yyy". The compiler can not locate the "xxx" so this error occurs.
You need to add the missing files(in this case "xxx") by right click on your project folder in navigator window and tap on "Add files to "YourProjectName"" option.
A popup window will open your project files in Finder. There, you can see the missing files and just add them to your project. Don't forget to check the "Copy items if needed" box. Good luck!!
I have also seen this error on Xcode 7.2 when the derived data becomes corrupted (in my case I interrupted a build and suspect that was the root cause).
So if the other solutions (notably Chris's and BraveS's which I suspect are more likely) do not fit your problem try deleting derived data (Select: Window / Projects / Derived Data -> Delete) and re-building.
(Added for reference by others - I know the original question has been answered correctly).
Under Xcode 9.0b5 you may encounter this because Xcode 9.0b5 has a bug in it where when you add source code, it does not honor the target settings. You must go in and set each file's target manually afterwords:
In my Case , it was not a library, it was some classes ..
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_ClassNmae", referenced from: objc-class-ref in
SomeClassName" . . .
d: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Solution
I had several targets in Xcode with several schemas ( Production , Dev etc ) .. some of my newly added implementation ( Class.m ) were missing in
Xcode->Targets->Build Phases->Compile Sources
So I had to add them manually.
then I could compile & build successfully.
I also encountered the same problem , the above methods will not work . I accidentally deleted the files in the following directory on it .
Or
~/Library/Developer/Xcode/DerivedData/
I tried just about everything here but my problem turned out to be the remnants of a previous cocoapods build. What worked for me was:
rm -Rf Pods; pod install
Delete Derived Data (Window/Projects... select your target. click Delete Button)
Rebuild
I have faced this issue many times. This usually comes when you delete your build folder.
The easy solution is to de-integrate and install the pod files again.
pod deintegrate
pod install
When updating to Xcode 7.1, you might see this type of error, and it can't be resolved by any of the above answers. One of the symptoms in my case was that the app runs on the device not in the simulator. You'll probably see a huge number of errors related to pretty much all of the frameworks you're using.
The fix is actually quite simple. You just need to delete an entry from the "Framework Search Paths" setting, found in your TARGETS > Build Settings > Search Paths section (make sure the "All" tab is selected)
If you see another entry here (besides $(inherited)) for your main target(s) or your test target, just delete the faulty path from all targets and rebuild.
I have found this can also occur if you drag a folder with Objective-C files into your project. If that folder appears blue I think it indicates its not properly linked. You can verify this (if you use version control) because whenever you add new files the pbxproj file should update with links to those new files. However you may find that after you added a folder that the pbxproj file did not change (and hence there is a linking error). So you will get auto-complete working and it will find the classes you imported, but when it goes to actually build the image it fails with this error code.
The solution is to not add the folder but rather add the files. Do this and you should see the pbxproj file update and it should fix this error.
This also assumes you've done what was suggested above and have properly linked all the right frameworks.
I know it's an old question but today got the same error and non of the above solutions worked.
Have fixed it however by setting option:
Project -> Architecture -> Build Active Architecture Only
to Yes
and project compiles and builds properly
I had the same error, because instead of deleting a file I simply removed references to it. Locating the file in Finder and removing it helped.
In my case, I built a custom framework with Deployment target set to 9.1, but the Deployment target of my app was lower, which supports 8.1. Minimize the custom framework Deployment target solved my problem.
If you're getting this error when trying to link to a C file, first double check the function names for typos. Next double check that you are not trying to call a C function from a C++ / Objective-C++ environment without using the extern C {} construct. I was tearing my hair out because I had a class that was in a .mm file which was trying to call C functions. It doesn't work because in C++, the symbols are mangled. You can actually see the concrete symbols generated using the nm tool. Terminal to the path of the .o files, and run nm -g on the file that is calling the symbol and the one that should have the symbol, and you should see if they match up or not, which can provide clues for the error.
nm -g file.o
You can inspect the C++ symbols demangled with this:
nm -gC file.o
I got it solved by adding "-lc++" in Other Linker Flags in Build Settings.
In my case problem was compiled framework architecture.
I'm running Xcode 11 and using Swift 5.1
I had 3 target like:
MyApp
MyAppTests
MyAppFrameWork
I was tried to run tests but MyAppFrameWork product was compiled for Generic iOS Devices and the Test target needed an arm x86-64, So I rebuilt Framework for iOS Simulators and test cases successfuly start running.
This is also happend with apple M1 chip.
Here is my solution just check Open using Rosetta
Steps:
Go to application > right click xcode > get info > check Open using Rosetta
Restart the system.
I am late to the party but thought of sharing one more scenario where this could happen.
I was working on a framework and was distributing it over cocoapods.
The framework had both objective c and swift classes and protocols and it was building successfully.
While using pod in another framework or project it was giving this error as I forgot to include .m files in podspec.
Please include .swtift,.h and .m files in your podspec sources as below:
s.source_files = "Projectname/Projectname/**/*.{swift,h,m}"
I hope it saves someone else's time.
in my case I had to add
target 'SomeTargetTests' do
inherit! :search_paths
end
to my podfile and then delete the /Pods directory and run `pod install`
(Xcode 10.1)
This might help somebody. It took me days to finally figure it out. I am working in OBJ-C and I went to:
Project -> Build Phases -> Compile sources and added the new VC.m file I had just added.
I am working with legacy code and I am usually a swifty, new to OBJ-C so I didn't even think to import my .m files into a sources library.
EDIT:
Ran into this problem a second time and it was something else. This answer saved me after 5 hours of debugging. Tried all of the options on this thread and more. https://stackoverflow.com/a/13625967/7842175 Please give him credit if this helps you, but basically you might need to set your file to its target in file inspector.
All in all, this is a very vague Error code that could be caused for a lot of reasons, so keep on trying different options.
What helped me was adding s.static_framework = true to my /podspec in the project that was throwing the error.
For me, this started to happen after merge conflict.
I tried to clean and remove build folder, but none of it helped. This issue kept happening regardless. Then I relinked the reference by deleting the groups that was problematic and re-added to the project and it worked.
Could also be an #include <windows.h> in the .c file that you're trying to compile.
Sometime, I forget to copy library from Release-universal and mistakenly copy from Release-iphoneos. Usually Release-iphoneos contains .a file which has been pruned for X86. and so it gives the error.
in my case, removing selection of target membership and then select again fix the issue.
Check William Cerniuk answer with the attachment photo.
Undefined symbols for architecture x86_64
I have run on this issue when used CocoaPods with some dependency which did not have specific version, that is why after pod update it downloaded the latest version which included some breaking changes
Upgrade dependencies and code for using them
Set specific version of pod
Remove Derived Data[About] folder
In my case I was getting this error: Undefined symbols for architecture x86_64: "_OBJC_CLASS _ $ _ RCTImageLoader"
And I was able to fix it by adding the following line in my Podfile file:
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
Reference
It happens when you are using architecture arm6, arm7 in your current project but any 3rd party framework which you are trying to consume in your project is built over x86_64.
For e.g If you are using Cocoa Pods in your project, then you need to add following script to make sure all 3rd party frameworks ensure arm6, arm7. i.e
Sample podfile with script to be add at end
target 'XYZ_ProjectTarget' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for XYZ_ProjectTarget
pod 'pod_name'
target 'XYZ_TargetTests' do
inherit! :search_paths
# Pods for testing
end
target 'XYZ_TargetUITests' do
# Pods for testing
end
end
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ARCHS'] = 'armv7 armv7s'
end
end
end

How to remove wrong path from $(inherited) at the project level?

I' getting linker warning when I try to build the project:
ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks'
I double checked framework search paths and it looks like $(inherited) contains invalid path. There's no such folder "Framework" in ".../Xcode.app/.../Library" - there are "GPUTools", "PrivateFrameworks" and "Xcode" folder. Of course this causes this warning to appear. Currently I'm trying to understand how Xcode creates this variable. Any ideas how to fix/remove wrong path from $(inherited)?
UPDATE I'm still using Xcode5, and cocoapods.
if you take a look at the project level build settings for the Framework search paths, this is where the target inherits from. Provided you do not manually provide these settings from a config-file, in that case you must fix it in that config-file.
UPDATE: When you use cocoa pods, you should remove the $(inherited) flag and let cocoa pods control this. You could delete everything cocoa pods-generated, except for your pods-file, and remove $(inherited) from your targets configuration, and rerun pod install. This should clear things up for you.
Cocoapods was not automatically controlling this field for me. I had to delete the line, go to the framework folder created by Cocoapods, Get Info, then copy-paste the "where" field. Then it worked.

Swift frameworks do not work with build configurations named other than 'Debug' or 'Release': No such module

Whenever I try to use a build configuration named other than 'Debug' or 'Release', Xcode suddenly cannot find my Swift frameworks. The configurations are the exact same other than their name (in fact, the new configuration was duplicated from the working 'Debug' configuration).
Xcode reports 'No such module'
This seems like a really strange bug. Surely someone has come across this before? My Google search yielded no results. Does anyone have any idea what may be causing this issue? I'm pretty sure I added the framework correctly.
I've created a short screencast to show you exactly what I'm doing: http://www.screencast.com/t/zpgZ5ZYgvH
Bottom line:
Make sure project currently builds using third-party Swift frameworks
Select the project in the project/file navigator
Select the project above Targets in the editor left sidebar and make sure you are on the Info tab
Duplicate the current configuration (likely 'Debug') by clicking the + button below the list of configurations and selecting 'Duplicate XXX Configuration'
Modify your scheme to use the new configuration by going to Product (menu) > Scheme > Edit Scheme...
Select Run in the left sidebar
Select your new configuration under Build Configuration
Attempt to build again
You can also download the sample project: http://s000.tinyupload.com/?file_id=48797763216274271820
I'm running Xcode 6.0.1 (6A317) and Yosemite 10.10 (14A361c).
Add the following Framework Search Path in the Build Settings of your target:
$(SYMROOT)/Release$(EFFECTIVE_PLATFORM_NAME)
and make it non-recursive
In my case this was for Alamofire, which was added to my project as a git submodule.
The framework was being built correctly which can be seen in the build logs, but I assume the default framework search path is derived from the scheme name. The Alamofire framework & dSYM file are in Release-iphoneos/ Release-iphonesimulator.
This should work work with any Swift framework as long as it's scheme names are default. If not, check the build logs and adjust the framework search path accordingly.
I had this issue as well and fixed it by adding the same configuration names to the included Alamofire project.
My build schemes in my main project:
And the build schemes inside the Alamofire project:
Note:
Also, make sure your iOS deployment target is the same in both projects.
If you are using CocoaPods, try pod install this will generate some .xcconfig files with your configuration name. Clean your build folder and build again.
If you have a modular structure (e.g. the App uses frameworks to decouple UI, Services or Business Logic from the application's main module) then add the new Build Configuration to each subproject that builds these frameworks.
In this case if the author had, let's say, Services Framework in his workspace then he had to add a Debug Original configuration to it too. And then run pod install, of course.
This is how I fixed my issue.

XCTest build errors for test target Xcode 5:

I have set up an XCode 5 iOS 7 project for unit tests.
Of course, setting up the unit tests are taking me so long that I'm trying to keep the faith that it's worth it. Struggling for hours over this error:
ld: building for iOS Simulator, but linking against dylib built for MacOSX file
'/Applications/Xcode5-DP5.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest'
for architecture i386
Any ideas on how to solve?
Check your Framework Search Paths in your test target settings. These can be corrupted when adding the XCTest Framework.
Adding XCTest to one of my projects prepended a "/" to the paths causing them to not find the correct version.
None of the above answers worked for me. I did find an answer here in a comment left by Tim Macfarlane.
For linker errors looking for a class in your app...
set the “Symbols Hidden by Default” build setting to “NO” in your app
target. This makes all your app classes available to your test target
automatically...
So, that means:
Project Navigator > Select your project
Targets > Select your App (not Tests)
Build Settings > Search for "Symbols Hidden By Default"
"Symbols Hidden By Default" > Change it from "YES" to "NO"
I had the same issue; the problem (for me, at least) was that the FRAMEWORKS_SEARCH_PATHS build setting listed the SDK frameworks folder after the main developer frameworks folder.
The frameworks included with Xcode have three separate builds: one for OS X, one for iOS (device), and a third for the iOS Simulator. The OS X build is in the main developer folder, with the other two being under their respective platform folders. The rub here is that if you don't specify to search the SDK folders first (which are within the platform folders), Xcode (or more correctly, the linker) will find the OS X build first and produce the error you see.
The solution is simple, put:
FRAMEWORK_SEARCH_PATHS = $(SDKROOT)/Developer/Library/Frameworks $(inherited)
in your build settings. If you're putting build settings in the project file (I don't recommend it, but that's another question for another day), it's just named "Framework search paths."
NOTE: Sometimes Xcode's a little slow to catch on; you'll probably need to delete your build folder (better than just a clean) for this to take effect.
Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:
"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)
So, for me, what I was missing after trying everything else in this post, was:
Other Linker Flags:
-framework XCTest
I'm currently using Xcode 6.0 (with the iOS 8 SDK) so I'm surprised that the "Edit > Refactor > Convert to XCTest..." option doesn't add this automatically.
I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.
I had this problem upon adding another file for tests.
If you do this with (CMD + N) be sure to only target
the Test Bundle (ie. 'AppNameTests').
I guess only these .xctest bundles have access to the
XCTest Framework.
I had the same issue after renaming my Target name and moving things around. It turned out that my tests were part of my Main Target. Make sure that you all your test files belong only to your test target.
Just select a .m file, make sure you have the right pane open.
I had the same problem when tried to build XCTTest-based unit tests with pre-7.0 SDK. When I chose 7.0 as my Base SDK then that kind of link error disappeared.
Had a the same issue but ended up with a slightly different solution.
select XCTest.framework and make sure that only your test folder is checked under Target Membership.
Make sure that the Search Framework Path (FRAMEWORK_SEARCH_PATHS) for the YourProjectTests target includes the path $(SDKROOT)/Developer/Library/Frameworks, and that this one is listed before $(inherited).
In my case, both paths were present, but $(inherited) was the first one.
Credit goes to https://stackoverflow.com/users/181947/brian-clear on Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

Resources