[英]Getting error: 'shared_ptr' in namespace 'std' does not name a type
I am trying to compile an android application in android studio (ndk r10d) which uses some C++ code.我正在尝试在使用一些 C++ 代码的 android studio (ndk r10d) 中编译一个 android 应用程序。 I needed C++11 so I added
-std=gnu++11
(I need gnu++11
instead of c++11
for an extension I am using).我需要 C++11,所以我添加了
-std=gnu++11
(对于我正在使用的扩展,我需要gnu++11
而不是c++11
)。 I am using the stlport stl, due to other libraries I am using that use this stl library.我正在使用 stlport stl,因为我使用的其他库使用了这个 stl 库。 So my cFlags and stl parameters in the build.gradle file looks like this:
所以我在 build.gradle 文件中的 cFlags 和 stl 参数如下所示:
stl "stlport_static"
cFlags " mylib1.a mylib2.a ... -fexceptions -frtti -std=gnu++11"
I also have included memory: #include <memory>
我也包含了内存:
#include <memory>
When trying to compile I receive this error:尝试编译时,我收到此错误:
'shared_ptr' in namespace 'std' does not name a type
I have been using the boost implementation for the smart pointers till now but with the move to c++11 I would rather use the standard implementation.到目前为止,我一直在使用智能指针的 boost 实现,但是随着转向 c++11,我宁愿使用标准实现。
http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared在您的代码中使用头文件。
#include <memory>
@TC Looks like you were right. @TC 看起来你是对的。 I saw your claim on a different question while looking for a solution for my problem, but as libraries that I am using are compiling with C++11 and STLport I thought that this claim might not be true.
在为我的问题寻找解决方案时,我看到了您在另一个问题上的声明,但由于我正在使用的库正在使用 C++11 和 STLport 进行编译,因此我认为此声明可能不正确。
What I think happened is that the libraries I'm using are not using any C++11 features that the STLport is missing.我认为发生的事情是我使用的库没有使用 STLport 缺少的任何 C++11 功能。 They are only using C++11 features that the gcc compiler supports.
它们仅使用 gcc 编译器支持的 C++11 功能。 I need the gnuStl to support the features that I am using.
我需要 gnuStl 来支持我正在使用的功能。
My solution was to use the boost implementation for the smart pointers and all other missing C++11 features.我的解决方案是对智能指针和所有其他缺少的 C++11 功能使用 boost 实现。
I got here googling for a similar error, but the answer did not work:我在这里搜索了类似的错误,但答案不起作用:
error: ‘shared_pointer’ in namespace ‘std’ does not name a template type
In my case, it was a typo:就我而言,这是一个错字:
std::shared_pointer
should be应该
std::shared_ptr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.