无法在Mac OSX上使用clang ++编译C ++ 17

问题描述 投票:0回答:2

clang ++版本:

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.

任何人都知道如何解决此问题吗?

c++ macos g++ c++17 clang++
2个回答
0
投票

您不见了


0
投票

[如果您查看compiler support page on cppreference,您会发现Apple Clang仍然不支持并行算法。

© www.soinside.com 2019 - 2024. All rights reserved.