Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Linker Error with the CouchCocoa.framework Archive build #36

Open
mattbond opened this issue Aug 6, 2012 · 11 comments
Open

Linker Error with the CouchCocoa.framework Archive build #36

mattbond opened this issue Aug 6, 2012 · 11 comments

Comments

@mattbond
Copy link
Contributor

mattbond commented Aug 6, 2012

After building the iOS Framework target using Product > Archive in Xcode Version 4.4 (4F250) and putting the framework into an bare bones iOS application created with the Xcode I get a linker error when trying to build the App to run on my iDevice.

This is the error:
ld: armv7 has no pc-rel bx thumb instruction. Can't fix up branch to NO BINDING in anon in anon from /Users/bond/Desktop/Archive/CouchCocoa.framework/CouchCocoa(CouchDynamicObject.o) for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Building to run on the iOS Simulator works fine.

If I use the Debug build of the CouchCocoa.framework it also compiles without problem.

To reproduce: Create the Archive build of the couchcocoa git master (commit 40a3aad)
Create an iOS application (e.g. with the Single View App Template)

Add the following to AppDelegate.m

  • #import <CouchCocoa/CouchCocoa.h>
  • 4 lines of code to application didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    CouchTouchDBServer* server = [CouchTouchDBServer sharedInstance];
    if (server.error) {
        return NO;
    }

    return YES;
}

Now connect an iDevice and try to run the app on the device. The build will fail with the linker error described.

I had the same problem in my real world app too.

I get the feeling this is a problem with Xcode 4.4 but I'm not sure. I will get an old Xcode installed asap and try that too asap.

@mattbond
Copy link
Contributor Author

mattbond commented Aug 6, 2012

Same problem with Xcode 4.3.3 on Lion

@mattbond mattbond closed this as completed Aug 6, 2012
@mattbond mattbond reopened this Aug 6, 2012
@snej
Copy link
Contributor

snej commented Aug 7, 2012

I just realized that you didn't say anything about linking against TouchDB, but the code you added to the app uses CouchTouchDBServer. That's not going to work. What frameworks are you linking the new app target against?

@mattbond
Copy link
Contributor Author

mattbond commented Aug 7, 2012

I'm also linking to:
QuartzCore.framework
libstdc++dylib
libz.dylib
libsqllite3.0.dylib
Security.framework
SystemConfiguration.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
CouchCocoa.framework
TouchDB.framework

@mattbond
Copy link
Contributor Author

mattbond commented Aug 7, 2012

My current workaround is to change the build Settings for CouchCocoa Debug to match those of Release (e.g. Max optimization, strip debug symbols etc etc.), then build a normal "Debug" build and use that CouchCocoa.framework in my App project.
I also had to do the same for TouchDB.framework
My App Archive now build fine.
Seems like an Archive build does something extra that isn't configured with the normal compiler params.
You're using -ObjC in TouchDB and CouchCocoa and I've got it in my App to (Otherwise TouchDB throws an exception anyway with a message to that effect in a normal debug build of the app).

I don't think it has anything to do with which other libraries I'm linking. The linker is complaining that in the compiled CouchDynamicObject.o there is an arm instruction (a particular thumb instruction) that isn't available on arm7. Why the compiler is producing such code in the Archive version I don't know.

http://opensource.apple.com/source/ld64/ld64-127.2/src/ld/OutputFile.cpp was the only reference to the message on google which is the linker code.

Or perhaps I am just missing a required framework in my App and in the Archive build the requires code is being stripped out of the framework and in the normal debug build is isn't getting stripped out?

@snej
Copy link
Contributor

snej commented Aug 7, 2012

Another thing to try is the Product > Build For > Archiving menu command, which will build the Release configuration but not archive the output. It'd be interesting to see if that builds or not.

@snej
Copy link
Contributor

snej commented Aug 7, 2012

Looking for anything related to Thumb, at the very bottom of the "iOS Library" target build settings I found a custom setting "GCC_THUMB_SUPPORT" set to NO. I have no idea where that came from — probably left over from the days of Xcode 4.1 before I was building with Clang, probably. Try deleting it and do a clean build and see if it helps.

@mattbond
Copy link
Contributor Author

mattbond commented Aug 7, 2012

I'll try it, but..
In my real world project I have two git-[sub]-modules one for couchcocoa and one for touchdb. And they are sub projects in my Xcode App project (i.e. Project dependencies). When I want to build an Archive of the App for the appstore or adhoc distribution it will alwats build the Archive version of the dependent CC & TDB frameworks.
I kept the example simple in my original post.

@mattbond
Copy link
Contributor Author

mattbond commented Aug 7, 2012

I saw the GCC_THUMB_SUPPORT too, but that sound more like don't use THUMB instructions atall, that makes sense for arm6 but not arm7 AFAIK, but either way it sounds like it shouldn't procuse thumb instructions, so it seems strange that the linker is having to fix them up

@snej
Copy link
Contributor

snej commented Aug 7, 2012

Try taking the GCC_THUMB_SUPPORT setting out anyway, and see if it changes anything.

@mattbond
Copy link
Contributor Author

mattbond commented Aug 8, 2012

OK, all tests done, and there's good news.
GCC_THUMB_SUPPORT makes no difference (to my archive linker problem) wether YES, NO or not present.
Product > Build For > Archiving builds a Release framework that works! - no linker problem and it runs fine on the device. SUPERB.

The only problem is that I now can't use my GIT submodules and Xcode subprojects as I would like to because when I want to make an Archive for AdHoc / AppStore deployment (Product > Archive) it would of course build both dependent subprojects (CouchCocoa and TouchDB) with Products > Archive too which produces unusable frameworks.
So I just need to build CouchCocoa and TouchDB separately now using Product > Build For Archive. I can live with that.

This is interesting: (unfortunately no replies)
http://stackoverflow.com/questions/7323528/different-binaries-with-archive-and-build-for-archiving-in-xcode4

Thanks for your support

@mdsec
Copy link

mdsec commented Feb 3, 2014

I had this error on a recent project and stumbled upon this thread while searching for possible resolutions. While I couldn't find any solution out there, after some investigation I managed to resolve it by setting the optimisation level for release builds to none. Hopefully this may help you also.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants