如何为最新的c++版本正确配置介子/忍者/qt创建者



我最近尝试运行一个使用智能指针的代码。正如标题所说,我使用Ninja(1.10.2版本(、Meson(0.57.2(和Qt Creator 4.14.2。我有以下介子构建:

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: []
)

但我仍然得到以下错误:

/~/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

对于以下线路:

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);
});

线程是这样声明的向量:

std::vector<std::unique_ptr<std::thread>> threads(height * width);

QtCreator文档表示,在这里使用Meson不支持某些功能,但这不包括编译器版本问题。

看起来介子选项一切都可以,你只是忘记添加<内存>标题(是的,错误消息有点混乱(:

#include <memory>
...

此外,这可能是由于为c++编译器设置了c_std选项,因为该选项用于c编译器。

也有可能生成目录未正确配置。要检查当前配置的选项和标志,您可以使用:

$ meson configure <build dir>

并且要重新配置:

$ meson setup --reconfigure <build dir>

顺便说一句(与问题无关(,这看起来很奇怪:

threads[height * width + width]  =

因为它与矢量重叠,不应该是吗?:

threads[invHeight * width + invWidth]  =

TL;DR

这个基本代码:

#include <iostream>
#include <memory>
int main()
{
std::cout << "Hello World!" << std::endl;
std::unique_ptr<int> a = std::make_unique<int>();
return 0;
}

不会起作用。编译器告诉我C++14或更高版本需要使用make_unique。问题是,我已经把";项目('ReadPool','cpp',default_options:['cpp_std=c++17']("在meson.build文件中,但由于某种原因,Qt Creator没有考虑这个文件:检查构建设置,选择的C++版本是C++11。

最新更新