在OSX Yosemite上使用Accelerate Framework进行编译

时间:2014-10-23 11:30:29

标签: c++ homebrew osx-yosemite accelerate-framework

我最近升级到优胜美地,但似乎在使用通过自制软件获得的gcc-4.9编译使用Accelerate Framework的C ++程序时出现问题。我想知道是否有人有任何解决方案吗?这在以前的OSX版本中不是问题。

例如,考虑编译以下代码。

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

使用clang进行编译时,每件事情都有效(Apple LLVM 6.0版(clang-600.0.54)):

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

但是用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

我收到以下编译错误:

    > 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);

   ^

1 个答案:

答案 0 :(得分:6)

这两个失败都是由GCC不支持的铿锵功能引起的。您可以使用clang而不是GCC,也可以解决它们。

第一个是<os/base.h>中的错误;它应该像__has_extension一样保护__has_builtin不被定义。您可以通过在包含系统头之前添加以下内容来解决此问题:

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

第二个问题是GCC不支持块。您应该能够通过在include之前添加以下内容来解决此问题:

#define vImage_Utilities_h
#define vImage_CVUtilities_h

这将阻止您使用某些vImage功能(即与Core Graphics和Core Video的简化互操作性),但您无法使用GCC的这些功能,所以您不会放弃任何东西。