简体   繁体   中英

Compiling with Accelerate Framework on OSX Yosemite

I have recently upgraded to Yosemite but seem to have a problem compiling C++ programs that use Accelerate Framework with the gcc-4.9 obtained through homebrew. I was wondering if anyone has any solutions for this? This was not a problem on previous OSX versions.

For as an example consider compiling the following code.

#include<iostream>
#include<Accelerate/Accelerate.h>
using namespace std;
{
return 0;
}

When compiling with clang every thing works (Apple LLVM version 6.0 (clang-600.0.54)) :

clang++ -flax-vector-conversions -o main.out main.cpp -framework Accelerate

But when compiling with g++-4.9 (g++-4.9 (Homebrew gcc49 4.9.1) 4.9.1) :

g++-4.9 -flax-vector-conversions -o main.out main.cpp -framework Accelerate

I get the following compile errors :

    > g++-4.9 -flax-vector-conversions -o main.out main.cpp -framework Accelerate
    In file included from /usr/include/os/object.h:27:0,
                     from /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/base.h:6,
                     from /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/LinearAlgebra.h:10,
                     from /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLib.h:65,
                     from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
                     from main.cpp:2:
    /usr/include/os/base.h:113:20: error: missing binary operator before token "("
     #if __has_extension(attribute_overloadable)
                        ^
    /usr/include/os/base.h:119:54: error: missing binary operator before token "("
     #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
                                                          ^
    In file included from /usr/include/dispatch/dispatch.h:51:0,
                     from /System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:56,
                     from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:8,
                     from /System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:41,
                     from /System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Utilities.h:14,
                     from /System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage.h:200,
                     from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:24,
                     from main.cpp:2:
    /usr/include/dispatch/object.h:143:15: error: expected unqualified-id before '^' token
     typedef void (^dispatch_block_t)(void);
                   ^
    /usr/include/dispatch/object.h:143:15: error: expected ')' before '^' token
    /usr/include/dispatch/object.h:362:3: error: 'dispatch_block_t' has not been declared
       dispatch_block_t notification_block);

   ^

Both failures are caused by clang features that GCC doesn't support. You can either use clang instead of GCC, or you can work around them.

The first one is a bug in <os/base.h> ; it should protect against __has_extension being undefined just like it does for __has_builtin , etc. You can work around this by putting the following before you include system headers:

#ifndef __has_extension
#define __has_extension(x) 0
#endif

The second issue is that GCC doesn't support blocks. You should be able to work around this by putting the following before the include:

#define vImage_Utilities_h
#define vImage_CVUtilities_h

This will prevent you from using some vImage features (namely, simplified interoperability with Core Graphics and Core Video), but you wouldn't have been able to use those features from GCC anyway, so you're not giving anything up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM