简体   繁体   English

GNU C ++:unique_ptr.h没有这样的文件或目录

[英]GNU C++: unique_ptr.h no such file or directory

I am cross compiling some code from Windows on Linux machine (Kubuntu 16.05),g++ 5.4.0 64bit. 我正在Linux机器(Kubuntu 16.05),g ++ 5.4.0 64bit上从Windows交叉编译一些代码。 Using Code Lite IDE as a dev env. 使用Code Lite IDE作为开发环境。 I have got several lines of code where I init unique pointer with 我有几行代码可以在其中初始化唯一指针

std::make_unique

The compiler complains with the error: 编译器报错:

error: 'make_unique' is not a member of 'std' 错误:“ make_unique”不是“ std”的成员

I tried to add <memory> as well as <unique_ptr.h> to the header. 我试图将<memory>以及<unique_ptr.h>到标题中。 Then the compiler complains that it can't find <unique_ptr.h> file. 然后,编译器抱怨找不到<unique_ptr.h>文件。 Interestingly,when I click to open the file from within the editor it is found and opened. 有趣的是,当我单击以从编辑器中打开文件时,该文件已找到并打开。 The file is located in /usr/include/c++/5/bits/unique_ptr.h 该文件位于/usr/include/c++/5/bits/unique_ptr.h

I made sure that the compiler version that builds the code is indeed 5.4, so I don't understand why it doesn't support unique_ptr out of the box.I make sure to enable C++11 and C++14 flags: 我确定构建代码的编译器版本确实是5.4,所以我不明白为什么它不支持即开即用的方式,我确保启用C ++ 11和C ++ 14标志:

-g;-O0;-std=c++14;-std=c++11;-Wall

Also, in the includes I add /user/include 此外,在包括我添加/ user / include

What am I missing here? 我在这里想念什么? Do I have to include in the project the /usr/include/c++/5/bits/ directory explicitly? 我是否必须在项目中明确/usr/include/c++/5/bits/目录?

Try these flags: -g -O0 -std=c++14 -Wall . 尝试以下标志: -g -O0 -std=c++14 -Wall Note that semicolon is not needed for separating flags. 请注意,不需要用分号来分隔标志。

Compiler will take the latest entry of -std so you are effectively compiling with C++11 but not C++14. 编译器将采用-std的最新条目,因此您可以使用C ++ 11而不是C ++ 14有效地进行编译。

As you can see HERE enabling -std=c++11 after a newer standard disables the first declared standard. 如您所见,在新的标准禁用第一个声明的标准之后,在此处启用-std=c++11 Enabling only C++14 is enough. 仅启用C ++ 14就足够了。

C++11 introduced std::unique_ptr , but there was no std::make_unique (this broke the "symmetry" of shared_ptr / make_shared ). C ++ 11引入了std::unique_ptr ,但是没有std::make_unique (这打破了shared_ptr / make_shared的“对称性”)。

They fixed that in C++14 , adding std::make_unique . 他们在C ++ 14中修复了此问题,添加了std::make_unique

So, if you compile your code in C++11 mode, you can't use std::make_unique . 因此,如果以C ++ 11模式编译代码,则不能使用std::make_unique

As others already pointed out, you need to set the latest C++ standard with the -std compiler option; 正如其他人已经指出的那样,您需要使用-std编译器选项设置最新的 C ++标准。 in this case, it's -std=c++14 to enable also std::make_unique . 在这种情况下, -std=c++14 可以启用std::make_unique

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM