c++ - 无法在 Mac OSX 上使用 clang++ 编译 C++17
问题描述
铿锵++版本:
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
尝试一些 C++ 并行性:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
#include <random>
#include <math.h>
#define N 10000000
double myFunction(double x) {
return pow(x, x) / (int(x) % 3);
}
int main() {
std::random_device rd;
std::uniform_real_distribution<double> uniform(0.0, 20.0);
std::vector<double> inputs;
std::vector<double> returnValues;
for (int i = 0; i < N; ++i) {
double r = uniform(rd);
inputs.push_back(r);
}
std::transform(std::execution::par_unseq,
inputs.begin(), inputs.end(),
returnValues.begin(),
myFunction);
}
我尝试使用所有这些进行编译:
$ clang++ -std=c++1z go.cpp -o run
$ clang++ -std=c++17 go.cpp -o run
有和没有#include <optional>
。但都提出了相同的编译器错误:
go.cpp:93:25: error: no member named 'execution' in namespace 'std'; did you mean 'exception'?
std::transform(std::execution::par_unseq,
~~~~~^~~~~~~~~
exception
/Library/Developer/CommandLineTools/usr/include/c++/v1/exception:97:29: note: 'exception' declared here
class _LIBCPP_EXCEPTION_ABI exception
^
go.cpp:93:36: error: no member named 'par_unseq' in 'std::exception'
std::transform(std::execution::par_unseq,
~~~~~~~~~~~~~~~~^
2 errors generated.
make: *** [parallel] Error 1
编辑:
尝试gcc
也不起作用:
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ gcc -ltbb -std=c++17 go.cpp -o run
$ gcc -ltbb go.cpp -o run
产生错误:
go.cpp:69:10: fatal error: 'execution' file not found
#include <execution>
^~~~~~~~~~~
1 error generated.
有人知道怎么修这个东西吗?
解决方案
如果您查看cppreference 上的编译器支持页面,您会注意到 Apple Clang 仍然不支持并行算法。
推荐阅读
- python - Pygame - 在两个矩形之间的碰撞过程中找到哪一侧击中
- swift - SceneKit 在同一几何体上使用具有不同纹理坐标的 2 种材质
- abap - 如何以有效的方式计算查询中的重复行?
- ansible - 是否可以对 vault_password_file 中的密码进行哈希处理以获取 ansible?
- ionic-framework - 打开本机相机后 Ionic App 崩溃 - 错误 20
- sql-server - Kubernetes 上的 SQL Server AG
- java - AccessibilityService能否在不打开应用的情况下对后台应用执行点击事件
- javascript - 为什么我不能得到 dateobject.getMonth() 的长度?
- java - 发送请求时出现此错误(java.net.ProtocolException:读取输入后无法写入输出。)
- javascript - 使用 Netlify 部署时如何修复“未找到这些依赖项:”,因为 yarn run serve 在本地机器上工作