如何在 C++17 中使用 <execution> 库

smi*_*mid 6 c++ c++17

学习如何使用 c++17 中的执行库。我正在使用 Linux,但也在我的 Mac 上尝试过。我收到此错误:

致命错误:找不到“执行”文件

当我在两个操作系统中编译时。

我宁愿坚持使用我输入的 linux:

g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread

也许我需要在-l....此处的参数中添加更多库。我是 C++ 的新手,不知道在哪里可以找到要添加的内容?我已经安装了 LLVM 并在类似的帖子上尝试了一些选项,但没有运气。有什么建议吗?

所以在我的 mac 上我做了 gcc -v 并得到:

gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin18.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

好的,更新 - 我现在切换到通过自制软件安装的 gcc-9.1。

没有像以前一样的“包含”错误,但是当我尝试编译使用 c++17 库的简单代码示例时,我现在遇到了这个问题:

g++-9 -std=c++17 example.cc In file included from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/parallel_backend.h:14, from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/algorithm_impl.h:25, from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/glue_execution_defs.h:52, from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/execution:3, from example.cc:6: /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/parallel_backend_tbb.h:19:10 fatal error: tbb/blocked_range.h: No such file or directory 19 | #include <tbb/blocked_range.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated.

我找到了丢失的库并编译如下:

g++-9 -std=c++17 example.cpp -I/usr/local/Cellar/tbb/2019_U8/include/ -I/usr/local/Cellar/tbb/2019_U8/lib/

我收到以下错误: Undefined symbols for architecture x86_64: "tbb::interface7::internal::task_arena_base::internal_current_slot()", referenced from: tbb::interface7::task_arena::current_thread_index() in ccnPixdL.o "tbb::interface7::internal::isolate_within_arena(t..........

接下来是许多类似的行......感觉我更接近但不知道如何继续这一行?

解决了 g++-9 -std=c++17 example.cpp -I/usr/local/Cellar/tbb/2019_U8/include/ -L/usr/local/Cellar/tbb/2019_U8/lib/ -ltbb

Ale*_*der 11

您需要安装 tbb 库。

在 Ubuntu/Linux 上:

$ sudo apt update
$ sudo apt install libtbb-dev
Run Code Online (Sandbox Code Playgroud)

在使用 Homebrew 的 Mac 上:

$ brew install tbb
Run Code Online (Sandbox Code Playgroud)

然后在 g++ 中链接运行时库:

g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread -ltbb
Run Code Online (Sandbox Code Playgroud)