问题描述
学习如何在c ++ 17中使用执行库。我正在使用Linux,但也在Mac上尝试过。我收到此错误:
Learning how to use the execution libraries in c++17. I am using Linux, but have also tried on my Mac. I get this error:
当我在两个OS上都进行编译时。
when i compile in both OS's.
我宁愿坚持使用linux,我在其中键入:
I would rather stick with linux where i type:
g ++ -g -std = c ++ 17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread
也许我需要在此处的 -l .... 参数中添加更多库。我是C ++的新手,不确定在哪里找到要添加的内容?我已经安装了LLVM,并在类似的帖子上尝试了一些选项,但是没有运气。有什么建议吗?
Perhaps I need to add some more libraries in the -l.... arguments here. I am new to c++ and not sure where to find out which ones to add? I have installed the LLVM and tried a few options out there on similar posts but with no luck. Any advice?
所以在我的Mac上,我做了gcc -v并得到了:
so on my mac i did gcc -v and got:
gcc -v配置为:--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版本10.0.0(clang-1000.11.45.5)目标:x86_64-apple-darwin18.6.0线程模型:posix InstalledDir:/ Applications / Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
好,所以更新-我现在切换到通过自制软件安装的gcc-9.1。
Ok, so an update- I am now switched to gcc-9.1 installed via homebrew.
没有以前的包含错误,但是当我尝试编译使用c +的简单代码示例时,我现在遇到了这个问题+17个库:
There are no "include" errors as before but I now have this issue when I try to compile simple code examples which use the c++17 libraries:
g ++-9 -std = c ++ 17 example.cc
在/ usr / local包含的文件中/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/parallel_backend.h:14,
来自/usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0 / ps tl / algorithm_impl.h:25,/ usr / local / Cellar / gcc / 9.1.0 / include / c ++ / 9.1.0 / pstl / glue_execution_defs.h:
,/ usr / local local / Cellar / gcc / 9.1.0 / include / c ++ / 9.1.0 / execution:3,
来自example.cc:6:
/usr/local/Cellar/gcc/9.1.0/ include / c ++ / 9.1.0 / pstl / parallel_backend_tbb.h:19:10致命错误:tbb / blocked_range.h:没有这样的文件或目录
19 | #include< tbb / blocked_range.h>
| ^ ~~~~~~~~~~~~~~~~~~~~
编译终止。
我找到了缺少的库并进行了编译,例如:
I found the missing library and compiled like:
g ++-9 -std = c ++ 17 example.cpp -I / usr / local / Cellar / tbb / 2019_U8 / include / -I / usr / local / Cellar / tbb / 2019_U8 / lib /
我遇到以下错误:
架构x86_64的未定义符号:
tbb :: interface7 :: internal :: task_arena_base :: internal_current_slot(),引用自:
tbb :: interface7 :: task_arena :: current_thread_index()
tbb :: interface7 :: internal :: isolate_within_arena(t ..........
后跟许多类似的行......感觉就像我靠近,但不知道如何继续前进吗?
followed by many lines of similar.....feel like im closer but no idea how to move on this one?
由 g ++-9 -std = c ++ 17 example.cpp -I / usr / local / Cellar / tbb / 2019_U8 / include / -L / usr / local / Cellar / tbb / 2019_U8 / lib / -ltbb
推荐答案
您需要安装tbb库。
在Ubuntu / Lin上ux:
On Ubuntu/Linux:
$ sudo apt update $ sudo apt install libtbb-dev
在Mac上使用Homebrew:
On Mac with Homebrew:
$ brew install tbb
然后在g ++中链接运行时库:
Then link runtime library in g++:
g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread -ltbb
这篇关于如何使用< execution> C ++ 17中的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!