Armadillo C++ 库 - C++11 编译器需要错误

问题描述

我使用 MacOS 10.15.7 和 Xcode 12.4,我想在我的 iOS Swift 项目中使用 Armadillo 库。所以首先我通过 Homebrew 安装了犰狳。

Armadillo 安装在路径 /usr/local/Cellar/armadillo/

我在路径 /usr/local/Cellar/armadillo/10.5.1/include 中找到头文件,在路径 /usr/local/Cellar/armadillo/10.5.1/lib 中找到库文件

在Xcode项目中,Build settings我在Header Search path和Library search path中提供了上述路径。

我遇到了以下三个错误。

  • /usr/local/Cellar/armadillo/10.5.1/include/armadillo_bits/compiler_check.hpp:50:4: error: "*** C++11 compiler required; enable C++11 mode in your compiler,or use an earlier version of Armadillo"
  • /usr/local/Cellar/armadillo/10.5.1/include/armadillo:23:10: error: 'cstdlib' file not found #include <cstdlib>
  • <unknown>:0: error: failed to emit precompiled header

不知道如何继续.. 任何建议???

解决方法

您将无法轻松做到这一点。 Swift 尚不支持 C++ 互操作,但这是一个长期目标。您可以在 Swift git repo 的 C++ Interop Manifesto 中阅读。您现在能做的最好的事情就是用 C++ 编写一个 extern "C" 包装器,围绕您要调用的任何 C++ 函数,然后将您的包装器导入 Swift。由于您使用的是 Xcode 项目,因此我建议您尝试使用 this 之类的东西。

或者,根据您需要犰狳的用途,如果没有它,您也可以过关。如果你只需要做线性代数,Apple 在 Accelerate 中包含 LAPACK(参见 here)和 BLAS(参见 here),无需安装任何东西即可在所有 Apple 平台上使用。这对您来说甚至可能很熟悉,因为 Armadillo 通过 LAPACK 进行矩阵分解。如果您正在寻找集成,还有 Quadrature(参见 here)。我对这些都有很好的体验。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...