c – 在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);
^
解决方法:
这两个失败都是由GCC不支持的clang功能引起的.您可以使用clang而不是GCC,也可以解决它们.
第一个是< os / base.h>中的错误;它应该像__has_builtin一样保护__has_extension不被定义.您可以通过在包含系统头之前添加以下内容来解决此问题:
#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的这些功能,因此您不会提供任何内容.
标签:accelerate-framework,c,homebrew,osx-yosemite 来源: https://codeday.me/bug/20190824/1713139.html