如何解决如何为最近的 C++ 版本正确配置 meson/ninja/qt creator?
我最近尝试运行一个使用智能指针的代码。正如标题所说,我使用 Ninja(版本 1.10.2)、Meson(0.57.2)和 Qt Creator 4.14.2。 我有以下 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: []
)
但我仍然收到以下错误:
/~/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);
Qt Creator 文档说使用 Meson here 不支持某些功能,但这不包括编译器版本问题。
解决方法
看起来介子选项一切正常,你只是忘记添加标题(是的,错误信息有点混乱):
#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;
}
不会工作。编译器告诉我使用 make_unique 需要 C++ 14 或 plus。问题是我已经在 meson.build 文件中放入了“project('ThreadPool','cpp',default_options : ['cpp_std=c++17'])”,但由于某种原因,这个文件没有被接受Qt Creator 帐户:检查构建设置是什么,选择的 C++ 版本是 C++11。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。