BergP
BergP

Reputation: 3545

Calling C function in Objective-C block (Linker error)

I have created C function:

header

//FileSystem.h file
#import <Foundation/Foundation.h>
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);

implementation

//FileSystem.mm
#import "FileSystem.h"
#import <sys/xattr.h>
#import <Support/Support.h>

static const char* attrName = "com.apple.MobileBackup";
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url) {
    BOOL operationResult = NO;
    // some implementation
    return operationResult;
}

When i'm calling AddSkipBackupAttributeToItemAtURL from another parts of application everything is OK, except one place where i'm calling function from the block.

__block UpdateFileAsyncOperation* selfOperation = self;
    _contentDownloader.completionBlock = ^(NSData* data) {
        [data saveForcedToPath:selfOperation.filePath];
        NSURL* fileUrlWithScheme = [NSURL fileURLWithPath:selfOperation.filePath];
        AddSkipBackupAttributeToItemAtURL(fileUrlWithScheme);
        [runLoop removePort:port forMode:NSDefaultRunLoopMode];
        [selfOperation completeOperation];
    };

In that place ,while linking in progress, there is error:

Undefined symbols for architecture i386:
"AddSkipBackupAttributeToItemAtURL", referenced from: __36-[UpdateFileAsyncOperation start]_block_invoke in UpdateFileAsyncOperation.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't understand why it happens, how it depends on block? and how can I fix that? Thanks!

Update: it is not dependent on block, i have moved calling of function to another place of class: the error still there. I'm trying to find why

Upvotes: 1

Views: 526

Answers (1)

BergP
BergP

Reputation: 3545

I have solved the problem. It not dependent on block. It dependent on file extensions.

The problem file was with ".m" extension, other files was with ".mm" extension.

So I have putted next macro in FileSystem.h file

#ifdef __cplusplus
extern "C" {
#endif

BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);

#ifdef __cplusplus
}
#endif

Upvotes: 7

Related Questions