Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use <execution> library in c++17

Tags:

c++

c++17

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:

fatal error: 'execution' file not found

when i compile in both OS's.

I would rather stick with linux where i type:

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

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?

so on my mac i did gcc -v and got:

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

Ok, so an update- I am now switched to gcc-9.1 installed via homebrew.

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 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.

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/

I got the following error: 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..........

followed by many lines of similar.....feel like im closer but no idea how to move on this one?

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

like image 286
smid Avatar asked Jul 17 '19 22:07

smid


1 Answers

You need to install tbb library.

On Ubuntu/Linux:

$ sudo apt update
$ sudo apt install libtbb-dev

On Mac with Homebrew:

$ brew install tbb

Then link runtime library in g++:

g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread -ltbb
like image 129
Alexander Avatar answered Nov 05 '22 04:11

Alexander