Search code examples
iosimportaccelerate-framework

iOS - Error parsing Accelerating Framework


I'm having this very weird problem, only in my project. I'm using XCode 4.3.6 and trying to add Accelerating Framework to my project. So in my file I just do a simple import statement:

#import <Accelerate/Accelerate.h>

And then I build my project and get 4 errors in the file clapack.h file of vecLib.framework pointing to these lines:

int claswp_(__CLPK_integer *n, __CLPK_complex *a, __CLPK_integer *lda, __CLPK_integer *
    k1, __CLPK_integer *k2, __CLPK_integer *ipiv, __CLPK_integer *incx) __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_4_0);

int dlaswp_(__CLPK_integer *n, __CLPK_doublereal *a, __CLPK_integer *lda, __CLPK_integer 
    *k1, __CLPK_integer *k2, __CLPK_integer *ipiv, __CLPK_integer *incx) __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_4_0);

int slaswp_(__CLPK_integer *n, __CLPK_real *a, __CLPK_integer *lda, __CLPK_integer *k1, 
    __CLPK_integer *k2, __CLPK_integer *ipiv, __CLPK_integer *incx) __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_4_0);

int zlaswp_(__CLPK_integer *n, __CLPK_doublecomplex *a, __CLPK_integer *lda, 
    __CLPK_integer *k1, __CLPK_integer *k2, __CLPK_integer *ipiv, __CLPK_integer *incx) __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_4_0);

All these errors showing that there's a missing expected closing bracket ')' at k1. It's weird that I don't get these errors in any other projects at all. What could be the reason for this error? I'd be really appreciate it if someone can suggest a solution for this.


Solution

  • Your code (or one of the headers that you include before <Accelerate/Accelerate.h>) defines a macro with the name k1. Something like:

    #define k1 *some expression*
    

    It’s a bug for a system library to use “common” parameter names like this for exactly this reason, but it’s also bad style for you to use them as macro names for the same reason.

    There are a few ways that you can resolve the issue:

    1. Change the name of your macro.
    2. Move the definition of your macro so that it comes after the inclusion of the Accelerate header.
    3. If you’re not using the LAPACK functions, but instead some other part of Accelerate, you can prevent the compiler from seeing the clapack.h prototypes via include-guard abuse:

       #define __CLAPACK_H // hide clapack.h prototypes
       #import <Accelerate/Accelerate.h>