Reputation: 49
I have tried to run a code which uses smart pointers recently. As the title says, I use Ninja (version 1.10.2), Meson (0.57.2) and Qt Creator 4.14.2. I have the following meson.build :
project('RayTracerDemo',
'cpp',
version: '0.0.0',
default_options: [
'c_std=c2x',
'cpp_std=c++20',
'warning_level=3',
'optimization=3',
'werror=true'
]
)
includeDir = include_directories([])
sources = files([
'main.cpp'
])
headers = files([])
raytracer_exe = executable(
'RayTracerDemo',
sources: sources + headers,
include_directories: includeDir,
dependencies: []
)
But I still get the following error :
/~/programs/RayTracerDemo/main.cpp:189: error: ‘make_unique’ is not a member of ‘std’
../main.cpp: In function ‘void render(const std::vector<Sphere>&)’:
../main.cpp:189:52: error: ‘make_unique’ is not a member of ‘std’
189 | threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
| ^~~~~~~~~~~
../main.cpp:189:52: note: ‘std::make_unique’ is only available from C++14 onwards
for the following lines :
threads[height * width + width] = std::make_unique<std::thread>([&]() -> void
{
float xx = (2 * ((x + 0.5) * invWidth) - 1) * angle * aspectratio;
float yy = (1 - 2 * ((y + 0.5) * invHeight)) * angle;
Vec3f raydir(xx, yy, -1);
raydir.normalize();
*pixel = trace(Vec3f(0), raydir, spheres, 0);
});
threads being a vector declared like so:
std::vector<std::unique_ptr<std::thread>> threads(height * width);
Qt Creator documentation says that some features aren't supported using Meson here, but this does not include compiler version issues.
Upvotes: 0
Views: 812
Reputation: 10997
It looks that everything is OK with meson options, you just forgot to add < memory> header (yes, error message is a bit confusing):
#include <memory>
...
Also, it could be due to setting c_std option for C++ compiler, since this option is for C compiler.
It's also possible that build directory is not (re)configured properly. To check currently configured options and flags you can with:
$ meson configure <build dir>
And to reconfigure:
$ meson setup --reconfigure <build dir>
BTW (it't nor related to question), this looks strange:
threads[height * width + width] =
as it overlaps the vector, shouldn't it be ? :
threads[invHeight * width + invWidth] =
This basic code :
#include <iostream>
#include <memory>
int main()
{
std::cout << "Hello World!" << std::endl;
std::unique_ptr<int> a = std::make_unique<int>();
return 0;
}
will not work. Compiler tells me C++ 14 or plus is required to use make_unique. The issue is that I already put "project('ThreadPool', 'cpp', default_options : ['cpp_std=c++17'])" in the meson.build file, but for some reason this file is just not taken in account by Qt Creator : checking what are the build settings, the C++ version chosen is C++11.
Upvotes: 1