Runtime linker error: dyld: Symbol not found: _NSURLIsExcludedFromBackupKey #394

Merged
merged 5 commits into from May 30, 2012

Conversation

Projects
None yet
10 participants
@onomated
Contributor

onomated commented May 28, 2012

Sharekit is resulting in the following runtime error on iPhone 5.0 simulator:
dyld: Symbol not found: _NSURLIsExcludedFromBackupKey
Referenced from: /Users/dev/Library/Application Support/iPhone Simulator/5.0/Applications/AA733E5E-02C3-4021-AE61-2F49106113E9/myapp.app/myapp
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Foundation
in /Users/dev/Library/Application Support/iPhone Simulator/5.0/Applications/AA733E5E-02C3-4021-AE61-2F49106113E9/myapp.app/myapp

My project is configured to build against the latest iOS sdk (i.e. 5.1) with a minimum deployment target of 5.0.

After investigating several solutions including macro bindings to iOS versions, this was the best solution I could find in the interim i.e. to remove the reference to the const string variable and insert the actual varialbe value directly. See:
http://stackoverflow.com/questions/10635607/nsurlisexcludedfrombackupkey-crashes-before-ios-5-1

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 29, 2012

Contributor

It is better to avoid magic string. The problem with the code is, that the if always evaluates to not nil - even on older iOS, where it should be nil.

Might you try this one? For me it works, though I do not understand why the former evaluation did not work.

NSString *const *key = &NSURLIsExcludedFromBackupKey;
    if (key) { // iOS >= 5.1
        return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    } else { //iOS <= 5.0.1 
        const char* filePath = [[URL path] fileSystemRepresentation];

        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;

        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    }
Contributor

VilemKurz commented May 29, 2012

It is better to avoid magic string. The problem with the code is, that the if always evaluates to not nil - even on older iOS, where it should be nil.

Might you try this one? For me it works, though I do not understand why the former evaluation did not work.

NSString *const *key = &NSURLIsExcludedFromBackupKey;
    if (key) { // iOS >= 5.1
        return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    } else { //iOS <= 5.0.1 
        const char* filePath = [[URL path] fileSystemRepresentation];

        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;

        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    }
@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 29, 2012

Contributor

This didn't work unfortunately. From everything I've read, the compiler attempts to evaluate all const variables even before main is executed. So the NSURLIsExcludedFromBackupKey in the pre 5.1 block gets evaluated always:

return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];

Some solutions on SO and some other blogs discuss weak linking, which supposedly should take place automatically with iOS SDK 4.2 and above:
http://stackoverflow.com/questions/3313786/ios-4-app-crashes-at-startup-on-ios-3-1-3-symbol-not-found-nsconcretestackbl
http://www.marco.org/2010/11/22/supporting-older-versions-of-ios-while-using-new-apis

But this will require linker flags that may affect overrall performance and differ for GDB and LLDB compilers. Haven't found the particular flag for LLDB yet.

I don't like the magic string idea also but its the only way to get around this that I'm aware of at the moment.

Contributor

onomated commented May 29, 2012

This didn't work unfortunately. From everything I've read, the compiler attempts to evaluate all const variables even before main is executed. So the NSURLIsExcludedFromBackupKey in the pre 5.1 block gets evaluated always:

return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];

Some solutions on SO and some other blogs discuss weak linking, which supposedly should take place automatically with iOS SDK 4.2 and above:
http://stackoverflow.com/questions/3313786/ios-4-app-crashes-at-startup-on-ios-3-1-3-symbol-not-found-nsconcretestackbl
http://www.marco.org/2010/11/22/supporting-older-versions-of-ios-while-using-new-apis

But this will require linker flags that may affect overrall performance and differ for GDB and LLDB compilers. Haven't found the particular flag for LLDB yet.

I don't like the magic string idea also but its the only way to get around this that I'm aware of at the moment.

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 29, 2012

Contributor

Wonder what is the difference between your project and the demo app? Because in the demo app this fix works well - prior this there was a crash too, but caused with if evaluation being always false.

Maybe the problem is in some specific project setting? Tested with iPhone 4.3 simulator

Contributor

VilemKurz commented May 29, 2012

Wonder what is the difference between your project and the demo app? Because in the demo app this fix works well - prior this there was a crash too, but caused with if evaluation being always false.

Maybe the problem is in some specific project setting? Tested with iPhone 4.3 simulator

@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 29, 2012

Contributor

That's a good point, I just duplicated all my project settings in the demo app and that loaded just fine. My setup is a bit different in that I build third party libraries into a single static lib project in my workspace which then gets linked into my app project. So it really looks like this is setup dependent.
I can close this request, or keep it open for reference till I investigate some more. What do you think is best?

Contributor

onomated commented May 29, 2012

That's a good point, I just duplicated all my project settings in the demo app and that loaded just fine. My setup is a bit different in that I build third party libraries into a single static lib project in my workspace which then gets linked into my app project. So it really looks like this is setup dependent.
I can close this request, or keep it open for reference till I investigate some more. What do you think is best?

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 29, 2012

Contributor

Have you tested it with my snippet, or with current ShareKit's master?

Contributor

VilemKurz commented May 29, 2012

Have you tested it with my snippet, or with current ShareKit's master?

@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 29, 2012

Contributor

Yes, I forked off the latest master. I also tried your snippet and got the same result. I can try simulating ShareKit in a static lib and linking that into the demo app i.e. as close to my setup as possible. My static library project uses the new install instructions to embed the project as a sub project.

Contributor

onomated commented May 29, 2012

Yes, I forked off the latest master. I also tried your snippet and got the same result. I can try simulating ShareKit in a static lib and linking that into the demo app i.e. as close to my setup as possible. My static library project uses the new install instructions to embed the project as a sub project.

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

Interesting, let's leave it opened. Wonder if someone else experiences this problem.

Contributor

VilemKurz commented May 30, 2012

Interesting, let's leave it opened. Wonder if someone else experiences this problem.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

Just fired up our stuff with the 4.3 simulator and encountered this problem...

Just fired up our stuff with the 4.3 simulator and encountered this problem...

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

could you test my snippet above, if it fixes the problem? For me it did, but for @onomated it did not make a difference... Maybe these are two independent errors

Contributor

VilemKurz commented May 30, 2012

could you test my snippet above, if it fixes the problem? For me it did, but for @onomated it did not make a difference... Maybe these are two independent errors

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

Doesn't work. It's the line;

return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];

That causes the look-up error, not &NSURLIsExcludedFromBackupKey. I've confirmed this by swapping the symbol for nil and recompiling.

Doesn't work. It's the line;

return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];

That causes the look-up error, not &NSURLIsExcludedFromBackupKey. I've confirmed this by swapping the symbol for nil and recompiling.

@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 30, 2012

Contributor

Here's a discussion on the apple forums which involves re-defining the symbol as a weak link import for the simulator only.
https://devforums.apple.com/message/630103#630103
My fear is that others have reported this on release builds also. So I'll stick with the "magic string" solution for now, since this methodology is deprecated as off 5.1, and I don't see this string changing ever in already released iOS versions.

Contributor

onomated commented May 30, 2012

Here's a discussion on the apple forums which involves re-defining the symbol as a weak link import for the simulator only.
https://devforums.apple.com/message/630103#630103
My fear is that others have reported this on release builds also. So I'll stick with the "magic string" solution for now, since this methodology is deprecated as off 5.1, and I don't see this string changing ever in already released iOS versions.

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

OK. +1 for onomated's fix. But still bugs me, why the heck is return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]; called on 4.3. It should not be called there. @jcmkodo, could you step trough the debugger to confirm this?

Contributor

VilemKurz commented May 30, 2012

OK. +1 for onomated's fix. But still bugs me, why the heck is return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]; called on 4.3. It should not be called there. @jcmkodo, could you step trough the debugger to confirm this?

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

it isn't called... but the symbols are all loaded at runtime, hence the fatal error. in any case, this can be fixed by adding;

#if TARGET_IPHONE_SIMULATOR
// +++ Working around <rdar://problem/11017158>> by forcing the symbol to be weak 
// in simulator builds.
extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import));
#endif

to Shk.m

it isn't called... but the symbols are all loaded at runtime, hence the fatal error. in any case, this can be fixed by adding;

#if TARGET_IPHONE_SIMULATOR
// +++ Working around <rdar://problem/11017158>> by forcing the symbol to be weak 
// in simulator builds.
extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import));
#endif

to Shk.m

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

Are you sure, that you build against latest iOS sdk (5.1)?

Contributor

VilemKurz commented May 30, 2012

Are you sure, that you build against latest iOS sdk (5.1)?

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

SDK 5.1, deployment target 3.1.3

SDK 5.1, deployment target 3.1.3

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

And if you raise the deployment target to 4.0? Anyway, I like the weak_import fix better than magic string. @onomated what do you think? Can you both test it also on device with release build?

Contributor

VilemKurz commented May 30, 2012

And if you raise the deployment target to 4.0? Anyway, I like the weak_import fix better than magic string. @onomated what do you think? Can you both test it also on device with release build?

@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 30, 2012

Contributor

I prefer the weak import directive myself and I have verified that works on the 5.0 simulator.

One particular concern is that this targets the iphone simulator only. A comment in this thread on SO reports the issue on release builds on actual devices:
http://stackoverflow.com/questions/9620651/use-nsurlisexcludedfrombackupkey-without-crashing-on-ios-5-0
(See Lukewar's comment)

So my proposed solution will be to remove the TARGET_IPHONE_SIMULATOR guard around the weak import directive.

Unfortunately I don't have a device with 5.0 to test with.

Contributor

onomated commented May 30, 2012

I prefer the weak import directive myself and I have verified that works on the 5.0 simulator.

One particular concern is that this targets the iphone simulator only. A comment in this thread on SO reports the issue on release builds on actual devices:
http://stackoverflow.com/questions/9620651/use-nsurlisexcludedfrombackupkey-without-crashing-on-ios-5-0
(See Lukewar's comment)

So my proposed solution will be to remove the TARGET_IPHONE_SIMULATOR guard around the weak import directive.

Unfortunately I don't have a device with 5.0 to test with.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

just confirmed on 4.2.1 and 5.1.1 devices, the weak_import is definitely necessary for pre 5.1 support, both device and simulator.

please let me know if i should test anything else.

just confirmed on 4.2.1 and 5.1.1 devices, the weak_import is definitely necessary for pre 5.1 support, both device and simulator.

please let me know if i should test anything else.

@onomated

This comment has been minimized.

Show comment
Hide comment
@onomated

onomated May 30, 2012

Contributor

Please test the latest changes I just committed. I removed the string constant workaround and added the weak import directive with a comment. Hopefully this is something we can remove in future releases of the iOS SDK.

Contributor

onomated commented May 30, 2012

Please test the latest changes I just committed. I removed the string constant workaround and added the weak import directive with a comment. Hopefully this is something we can remove in future releases of the iOS SDK.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 30, 2012

confirmed all ok with those fixes

confirmed all ok with those fixes

VilemKurz added a commit that referenced this pull request May 30, 2012

Merge pull request #394 from onomated/master
Runtime linker error: dyld: Symbol not found: _NSURLIsExcludedFromBackupKey

@VilemKurz VilemKurz merged commit c2d0db6 into ShareKit:master May 30, 2012

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 30, 2012

Contributor

+1 and merging, as this is hotfix, and has been tested. Thanks guys.

Contributor

VilemKurz commented May 30, 2012

+1 and merging, as this is hotfix, and has been tested. Thanks guys.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 31, 2012

Problems! We have discovered today that our archived builds are no longer opening on devices prior to 5.1. I think it's pretty safe to assume that yesterday's fix is somehow cancelled out by an archived build. Seems this issue needs to be reopened, sorry

Problems! We have discovered today that our archived builds are no longer opening on devices prior to 5.1. I think it's pretty safe to assume that yesterday's fix is somehow cancelled out by an archived build. Seems this issue needs to be reopened, sorry

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 31, 2012

Contributor

Aren't these archives built prior fixing? Weren't they built with #if TARGET_IPHONE_SIMULATOR? Archives are built for device ...

Contributor

VilemKurz commented May 31, 2012

Aren't these archives built prior fixing? Weren't they built with #if TARGET_IPHONE_SIMULATOR? Archives are built for device ...

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 31, 2012

As noted above, the weak import fix is required for simulator and device. I confirmed this on devices yesterday. That an archive build breaks the fix, though, was unexpected

As noted above, the weak import fix is required for simulator and device. I confirmed this on devices yesterday. That an archive build breaks the fix, though, was unexpected

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 31, 2012

Contributor

Yeah, I just wanted to make sure that the archive was done with the current version. We should fix this asap, though I will not be available on monday... :(

Contributor

VilemKurz commented May 31, 2012

Yeah, I just wanted to make sure that the archive was done with the current version. We should fix this asap, though I will not be available on monday... :(

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 31, 2012

Definitely the updated version

Definitely the updated version

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz May 31, 2012

Contributor

Probably we should take the original magic string approach from @onomated if it proves the archive strips the fix. If there is a pull request, I might merge it sooner than on monday (I will be online, though not on dev machine).

Contributor

VilemKurz commented May 31, 2012

Probably we should take the original magic string approach from @onomated if it proves the archive strips the fix. If there is a pull request, I might merge it sooner than on monday (I will be online, though not on dev machine).

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 May 31, 2012

Unlikely to be able to look at this until at least tomorrow now.

Unlikely to be able to look at this until at least tomorrow now.

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jun 1, 2012

Contributor

FIXED!!!

Stupid me, sorry guys. Deployment target was set to 5.1 on library targets. Sorry again. Please update. In case it does not work, do not forget to clean the project and build folder.

Contributor

VilemKurz commented Jun 1, 2012

FIXED!!!

Stupid me, sorry guys. Deployment target was set to 5.1 on library targets. Sorry again. Please update. In case it does not work, do not forget to clean the project and build folder.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 Jun 1, 2012

That's great news! I can double check for you that it's working our end a little later

That's great news! I can double check for you that it's working our end a little later

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 Jun 1, 2012

Seems to be working now, thanks. I notice that the library is deployment target 4.0. Is this the lowest it ever was? Unfortunately I'm still obliged to support min 3.1.3...

Seems to be working now, thanks. I notice that the library is deployment target 4.0. Is this the lowest it ever was? Unfortunately I'm still obliged to support min 3.1.3...

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jun 1, 2012

Contributor

We dropped older ioses support, unfortunately. It might work with some customizations, i remember there was one issue with hints...

Contributor

VilemKurz commented Jun 1, 2012

We dropped older ioses support, unfortunately. It might work with some customizations, i remember there was one issue with hints...

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 Jun 1, 2012

Ok, no need to apologise - unfortunately we have some very unrealistic clients! Not sure how I'll tackle this for now... May not end up being my problem

Ok, no need to apologise - unfortunately we have some very unrealistic clients! Not sure how I'll tackle this for now... May not end up being my problem

@programmerdave

This comment has been minimized.

Show comment
Hide comment
@programmerdave

programmerdave Jun 3, 2012

Hi, this is still crashing on a 4.1 device. It's difficult to test this through the simulator. The best way I found is to archive it and put it on Test Flight. I keep getting:

dyld: Symbol not found: _NSURLIsExcludedFromBackupKey

Hi, this is still crashing on a 4.1 device. It's difficult to test this through the simulator. The best way I found is to archive it and put it on Test Flight. I keep getting:

dyld: Symbol not found: _NSURLIsExcludedFromBackupKey

@bchessin

This comment has been minimized.

Show comment
Hide comment
@bchessin

bchessin Jun 3, 2012

Contributor

If this whole issue is for adding the backup attribute to all versions, please update to the latest ShareKit. Some updated code was just merged about an hour ago.

Contributor

bchessin commented Jun 3, 2012

If this whole issue is for adding the backup attribute to all versions, please update to the latest ShareKit. Some updated code was just merged about an hour ago.

@programmerdave

This comment has been minimized.

Show comment
Hide comment
@programmerdave

programmerdave Jun 3, 2012

I'm using the latest commit. It still doesn't work when the build is archived.

I'm using the latest commit. It still doesn't work when the build is archived.

@bchessin

This comment has been minimized.

Show comment
Hide comment
@bchessin

bchessin Jun 4, 2012

Contributor

Make sure the deployment target is at least iOS 4 in order to get rid of this issue. Thats what fixed the issue for others.

Contributor

bchessin commented Jun 4, 2012

Make sure the deployment target is at least iOS 4 in order to get rid of this issue. Thats what fixed the issue for others.

@wujun

This comment has been minimized.

Show comment
Hide comment
@wujun

wujun Jun 4, 2012

NSURLIsExcludedFromBackupKey can't be compiled under ios version which is smaller than 5.1. so should add a preprocessor directive to determine which version you are using at compile time like this:

ifndef NSURLIsExcludedFromBackupKey

u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;

else

if (&NSURLIsExcludedFromBackupKey == nil) 
{
    // iOS 5.0.1 and lower
    u_int8_t attrValue = 1;
    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}
else 
{
    // First try and remove the extended attribute if it is present
    int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
    if (result != -1) 
    {
        // The attribute exists, we need to remove it
        int removeResult = removexattr(filePath, attrName, 0);
        if (removeResult == 0) 
        {
            NSLog(@"Removed extended attribute on file %@", URL);
        }
    }

    // Set the new key
    return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}

endif

wujun commented on 99546be Jun 4, 2012

NSURLIsExcludedFromBackupKey can't be compiled under ios version which is smaller than 5.1. so should add a preprocessor directive to determine which version you are using at compile time like this:

ifndef NSURLIsExcludedFromBackupKey

u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;

else

if (&NSURLIsExcludedFromBackupKey == nil) 
{
    // iOS 5.0.1 and lower
    u_int8_t attrValue = 1;
    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}
else 
{
    // First try and remove the extended attribute if it is present
    int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
    if (result != -1) 
    {
        // The attribute exists, we need to remove it
        int removeResult = removexattr(filePath, attrName, 0);
        if (removeResult == 0) 
        {
            NSLog(@"Removed extended attribute on file %@", URL);
        }
    }

    // Set the new key
    return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}

endif

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jun 4, 2012

Contributor

I confirm, that the issue exists, but you can reproduce it only if you run an archived app on device < iOS 5.1. None of the fixes above works.

The only workaround is to add CoreFoundation framework and make it optional. I am going to update install guide appropriately.

Contributor

VilemKurz commented Jun 4, 2012

I confirm, that the issue exists, but you can reproduce it only if you run an archived app on device < iOS 5.1. None of the fixes above works.

The only workaround is to add CoreFoundation framework and make it optional. I am going to update install guide appropriately.

@programmerdave

This comment has been minimized.

Show comment
Hide comment
@programmerdave

programmerdave Jun 5, 2012

Adding the CoreFoundation framework and making optional works! Thanks VilemKurz.

wujun: You can't do that since you can compile with ios5.1 sdk and set the deployment target to something lower. So it's not a compile time issue.

Adding the CoreFoundation framework and making optional works! Thanks VilemKurz.

wujun: You can't do that since you can compile with ios5.1 sdk and set the deployment target to something lower. So it's not a compile time issue.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 Jun 6, 2012

Me again,

Just did a build on a machine that only has 5.0 SDK (Xcode 4.2 on Snow Leopard). Won't build due to lack of preprocessor defines. Needs something like;

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    const char* filePath = [[URL path] fileSystemRepresentation];
    const char* attrName = "com.apple.MobileBackup";
#ifdef __IPHONE_5_0_1
    if (&NSURLIsExcludedFromBackupKey == nil) {
#endif
        // iOS 5.0.1 and lower
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
#ifdef __IPHONE_5_0_1
    }
    else {
        // First try and remove the extended attribute if it is present
        int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
        if (result != -1) {
            // The attribute exists, we need to remove it
            int removeResult = removexattr(filePath, attrName, 0);
            if (removeResult == 0) {
                NSLog(@"Removed extended attribute on file %@", URL);
            }
        }

        // Set the new key
        return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    }
#endif
}

Not sure that __IPHONE_5_0_1 is correct, though

Me again,

Just did a build on a machine that only has 5.0 SDK (Xcode 4.2 on Snow Leopard). Won't build due to lack of preprocessor defines. Needs something like;

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    const char* filePath = [[URL path] fileSystemRepresentation];
    const char* attrName = "com.apple.MobileBackup";
#ifdef __IPHONE_5_0_1
    if (&NSURLIsExcludedFromBackupKey == nil) {
#endif
        // iOS 5.0.1 and lower
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
#ifdef __IPHONE_5_0_1
    }
    else {
        // First try and remove the extended attribute if it is present
        int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
        if (result != -1) {
            // The attribute exists, we need to remove it
            int removeResult = removexattr(filePath, attrName, 0);
            if (removeResult == 0) {
                NSLog(@"Removed extended attribute on file %@", URL);
            }
        }

        // Set the new key
        return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    }
#endif
}

Not sure that __IPHONE_5_0_1 is correct, though

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jun 6, 2012

Contributor

Sorry, it is everybody's "duty" to use latest SDK. If you wish to use older sdk, please support it in your fork.

Contributor

VilemKurz commented Jun 6, 2012

Sorry, it is everybody's "duty" to use latest SDK. If you wish to use older sdk, please support it in your fork.

@daviddoyle1571

This comment has been minimized.

Show comment
Hide comment
@daviddoyle1571

daviddoyle1571 Jun 6, 2012

ok, apologies for that. if it were up to me, we would...

ok, apologies for that. if it were up to me, we would...

@akaspick

This comment has been minimized.

Show comment
Hide comment
@akaspick

akaspick Jun 18, 2012

Can you update the install guide to specifically state that installing ShareKit requires Xcode 4.3+ and SDK 5.1+ ?

SDK 5.1 isn't supported under Xcode 4.2, so making it a requirement to use SDK 5.1 also makes Xcode 4.3 a requirement.

Can you update the install guide to specifically state that installing ShareKit requires Xcode 4.3+ and SDK 5.1+ ?

SDK 5.1 isn't supported under Xcode 4.2, so making it a requirement to use SDK 5.1 also makes Xcode 4.3 a requirement.

@akaspick

This comment has been minimized.

Show comment
Hide comment
@akaspick

akaspick Jun 18, 2012

Oh, and Xcode 4.3 requires OSX Lion. For those not up to date on all their Mac software, one of the other hacks may be required to overcome this issue if upgrading isn't an option at the moment.

Oh, and Xcode 4.3 requires OSX Lion. For those not up to date on all their Mac software, one of the other hacks may be required to overcome this issue if upgrading isn't an option at the moment.

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jun 19, 2012

Contributor

changed wiki. Thank you for suggestion.

Contributor

VilemKurz commented Jun 19, 2012

changed wiki. Thank you for suggestion.

@phoenixsampras

This comment has been minimized.

Show comment
Hide comment
@phoenixsampras

phoenixsampras Jul 12, 2012

[quote]Adding the CoreFoundation framework and making optional works! Thanks VilemKurz. [/quote]

Excuse me, but how to make it OPTIONAL???

[quote]Adding the CoreFoundation framework and making optional works! Thanks VilemKurz. [/quote]

Excuse me, but how to make it OPTIONAL???

@VilemKurz

This comment has been minimized.

Show comment
Hide comment
@VilemKurz

VilemKurz Jul 12, 2012

Contributor

your target - build phases - link binary with libraries - change "required" to "optional"

Contributor

VilemKurz commented Jul 12, 2012

your target - build phases - link binary with libraries - change "required" to "optional"

@phoenixsampras

This comment has been minimized.

Show comment
Hide comment
@phoenixsampras

phoenixsampras Aug 23, 2012

It started to work for me after reinstalling the kit. For me.
On Aug 22, 2012 11:38 AM, "Ramiro Aparicio" notifications@github.com
wrote:

I don't know why but even while I can compile the project correctly with
XCode 4.4.1 I can not compile it using command line tools even after making
it optional.

Maybe as this seems to cause too many errors (and the fix is more a hack
than a fix) we should start looking to other ways to make it backwards
compatible.


Reply to this email directly or view it on GitHubhttps://github.com/ShareKit/ShareKit/pull/394#issuecomment-7938423.

It started to work for me after reinstalling the kit. For me.
On Aug 22, 2012 11:38 AM, "Ramiro Aparicio" notifications@github.com
wrote:

I don't know why but even while I can compile the project correctly with
XCode 4.4.1 I can not compile it using command line tools even after making
it optional.

Maybe as this seems to cause too many errors (and the fix is more a hack
than a fix) we should start looking to other ways to make it backwards
compatible.


Reply to this email directly or view it on GitHubhttps://github.com/ShareKit/ShareKit/pull/394#issuecomment-7938423.

@friscoMad

This comment has been minimized.

Show comment
Hide comment
@friscoMad

friscoMad Aug 23, 2012

Sorry it was my fault I deleted the comment after posting it.
I had an old 1.2.2 XCode installation and it seems that Command Line tools took that instead of 1.4.4 after removing the old XCode installation everything compiled as it should.

Sorry it was my fault I deleted the comment after posting it.
I had an old 1.2.2 XCode installation and it seems that Command Line tools took that instead of 1.4.4 after removing the old XCode installation everything compiled as it should.

@herrernst

This comment has been minimized.

Show comment
Hide comment
@herrernst

herrernst Aug 28, 2012

Contributor

I think I have followed all steps, but I still have problems with archive builds.

For me, it seems that weak linking Foundation solves the problem with previous Simulators (in my case 5.0) not working (dyld: Symbol not found: _NSURLIsExcludedFromBackupKey).

But unfortunately, I have another problem, that is with archive builds (XCode 4.4.1). When starting the app on a 5.0 device, it works, when archiving and then moving the IPA-file to the device, it doesn't. Seems that when archiving, the linker changes something.

In the Apple developer forums https://devforums.apple.com/message/630103#630103 I have found a way to check if the required symbol (in this case: NSURLIsExcludedFromBackupKey) is weak linked or not:

When I build (Debug or Release) and go to the DerivedData, I can check the product thus:

nm -m TestApp.app/TestApp | grep NSURLIsExcludedFromBackupKey
         (undefined) weak external _NSURLIsExcludedFromBackupKey (from CoreFoundation)

When I check the archived build via "Show Package Contents" of the archive, I get this:

nm -m Products/Applications/TestApp.app/TestApp | grep NSURLIsExcludedFromBackupKey
         (undefined) external _NSURLIsExcludedFromBackupKey (from CoreFoundation)

(Notice the missing "weak")

I don't know why it is that way, and how to "correctly" fix it; this fix posted on Stack Overflow might work, but I have not tested it:

http://stackoverflow.com/questions/10300800/ios-app-with-static-lib-always-crashes-on-launch-of-ad-hoc-archive-build-cant-r/10302012#10302012

For me, weak linking also seems to work on archive builds if I additionally reference the symbol in the main program, i. e. not in the static library.

I have not rechecked everything I've written above, so it might not be completely correct, but maybe it helps somebody solving his/her issues.

Contributor

herrernst commented Aug 28, 2012

I think I have followed all steps, but I still have problems with archive builds.

For me, it seems that weak linking Foundation solves the problem with previous Simulators (in my case 5.0) not working (dyld: Symbol not found: _NSURLIsExcludedFromBackupKey).

But unfortunately, I have another problem, that is with archive builds (XCode 4.4.1). When starting the app on a 5.0 device, it works, when archiving and then moving the IPA-file to the device, it doesn't. Seems that when archiving, the linker changes something.

In the Apple developer forums https://devforums.apple.com/message/630103#630103 I have found a way to check if the required symbol (in this case: NSURLIsExcludedFromBackupKey) is weak linked or not:

When I build (Debug or Release) and go to the DerivedData, I can check the product thus:

nm -m TestApp.app/TestApp | grep NSURLIsExcludedFromBackupKey
         (undefined) weak external _NSURLIsExcludedFromBackupKey (from CoreFoundation)

When I check the archived build via "Show Package Contents" of the archive, I get this:

nm -m Products/Applications/TestApp.app/TestApp | grep NSURLIsExcludedFromBackupKey
         (undefined) external _NSURLIsExcludedFromBackupKey (from CoreFoundation)

(Notice the missing "weak")

I don't know why it is that way, and how to "correctly" fix it; this fix posted on Stack Overflow might work, but I have not tested it:

http://stackoverflow.com/questions/10300800/ios-app-with-static-lib-always-crashes-on-launch-of-ad-hoc-archive-build-cant-r/10302012#10302012

For me, weak linking also seems to work on archive builds if I additionally reference the symbol in the main program, i. e. not in the static library.

I have not rechecked everything I've written above, so it might not be completely correct, but maybe it helps somebody solving his/her issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment