3

So I'm trying to create a new C++17 cmake project in QtCreator 4.8.1 and I've run into a small hiccup. It seems I'm using the correct linker and compiler but there must be a setting I'm missing somewhere as the (small) project I've done won't build.

g++-9 was not in Ubuntu so the first thing I did was install it (and gcc-9 too). Then I created a new kit and changed the C/C++ compiler to that one. I did not other changes to it.

#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>

using namespace std;

int main()
{
    std::cout << __cplusplus << std::endl;

    std::vector<int> vec ={3, 2, 1, 4, 5, 6, 10, 8, 9, 4};

    std::sort(vec.begin(), vec.end());                            // sequential as ever
    std::sort(std::execution::seq, vec.begin(), vec.end());       // sequential
    std::sort(std::execution::par, vec.begin(), vec.end());       // parallel
    std::sort(std::execution::par_unseq, vec.begin(), vec.end()); // parallel and vectorized

    return 0;
}

Alas although I can follow the header into the correct more recent version the build system still complains std::execution::seq does not exist (and __cplusplus seems to keep pointing to the 2014 one)

edit: I've tried following suggestions in similar questions by adding set(CMAKE_CXX_STANDARD 17) to my cmake file but now I'm getting

In file included from /usr/include/c++/9/pstl/parallel_backend.h:14,
                 from /usr/include/c++/9/pstl/algorithm_impl.h:25,
                 from /usr/include/c++/9/pstl/glue_execution_defs.h:52,
                 from /usr/include/c++/9/execution:32,
                 from /home/pedro/LockLessDt/main.cpp:4:
/usr/include/c++/9/pstl/parallel_backend_tbb.h:19:10: fatal error: tbb/blocked_range.h: No such file or directory
      |          ^~~~~~~~~~~~~~~~~~~~~

Which sounds like a problem with the execution header.

__cplusplus now points to the correct value though.

This is my cmake file

cmake_minimum_required(VERSION 2.8)
project(LockLessDt)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} "main.cpp")
Kronephon
  • 325
  • 3
  • 12
  • 3
    Are you specifying the `-std=c++17` flag explicitly in your compiler options? I'm currently using `g++` 9.2.1 and the default standard used appears to be `c++14`. – G.M. Sep 13 '19 at 10:08
  • Possible duplicate of [Can't use c++17 features using g++ 7.2 in QtCreator](https://stackoverflow.com/questions/46610996/cant-use-c17-features-using-g-7-2-in-qtcreator) – Alan Birtles Sep 13 '19 at 10:28
  • This is the version of `Qt` that is important, not the version of `Qt Creator`. And yes, certainly a duplicate. – Fareanor Sep 13 '19 at 10:30
  • 1
    @Fareanor I'd argue that in this case both the `Qt` and `Qt Creator` versions are irrelevant. From the descriptions it seems to boil down to "how to enable C++17 features in my CMake project". – Dan M. Sep 13 '19 at 10:50
  • 1
    Possible duplicate of [QtCreator Cmake C++17 Features](https://stackoverflow.com/questions/48501290/qtcreator-cmake-c17-features) – Ruslan Sep 13 '19 at 10:56
  • @DanM. You're right, I didn't pay enough attention. – Fareanor Sep 13 '19 at 10:59
  • @Kronephon: It is `CMakeLists.txt` which is responsible for specifying C++ standard, include directories, linked libraries and so on. But you question doesn't contain that file. How should we find the problems in the file we don't see? See also [ask]. – Tsyvarev Sep 13 '19 at 12:11
  • @Tsyvarev added it in. Thanks! – Kronephon Sep 13 '19 at 12:54
  • Does given code cause the error about `tbb/blocked_range.h`? Please, add to the question post the **exact error message**. For the future: The code and the error message are required in almost any Stack Overflow question about problems with the code. – Tsyvarev Sep 13 '19 at 12:59
  • @Tsyvarev, the only reason I had not added it in, was because this was a development from reading answers here. Added it now. – Kronephon Sep 13 '19 at 13:04
  • I understand that your question has been changed since the first time. This is not a problem, unless changes invalidates the answers you got. This is why it is so important to correctly describe the problem in the original post. As for the error message, it should also contain an *include chain*. This chain is started from the your source file (`main.cpp`) and ends at the file which contains the erroneous statement. Currently your message contains only the last file, but in many cases the chain is important too. – Tsyvarev Sep 13 '19 at 13:11
  • Thanks, QtCreator typically hides it. Added it in. – Kronephon Sep 13 '19 at 13:15
  • Well, the question becomes clear now. By the way, you have the error message similar to the one in [another question](https://stackoverflow.com/questions/57084789/how-to-use-execution-library-in-c17). That question doesn't related to QT or CMake. While it doesn't have an answer, the asker seems have found a way to overcome the problem. – Tsyvarev Sep 13 '19 at 14:16

1 Answers1

3

I suppose someone here had a similar problem.

As you are using CMake maybe try setting:

set(CMAKE_CXX_STANDARD 17)
Kyeiv
  • 63
  • 8
  • Tried it and it seems that now I'm getting an odder error. tbb/blocked_range.h: No such file or directory – Kronephon Sep 13 '19 at 11:55