简体   繁体   English

获取错误:命名空间“std”中的“shared_ptr”未命名类型

[英]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.

相关问题 ndk-build错误:名称空间“ std”中的“字符串”未命名类型 - ndk-build error: 'string' in namespace 'std' does not name a type 错误:没有匹配的构造函数来初始化&#39;std :: shared_ptr <uint8_t []> “ - Error: no matching constructor for initialization of 'std::shared_ptr<uint8_t []>' Android 原生强指针与 std::shared_ptr - Android native strong pointer vs std::shared_ptr android-ndk-r6-crystax-2错误:名称空间“ std”中的“字符串”未命名类型 - android-ndk-r6-crystax-2 error: 'string' in namespace 'std' does not name a type 共享的Xamarin.Forms-类型或名称空间名称&#39;App&#39;在名称空间中不存在 - Shared Xamarin.Forms - The type or namespace name 'App' does not exist in the namespace 错误 CS0234 命名空间“Xamarin.Forms.Platform”中不存在类型或命名空间名称“Android” - Error CS0234 The type or namespace name 'Android' does not exist in the namespace 'Xamarin.Forms.Platform SWIG和shared_ptr:javaout typemap不适用于地图模板 - SWIG and shared_ptr: javaout typemap not applied to map template Unity 中的命名空间“UnityEngine”中不存在类型或命名空间名称“Windows” - The type or namespace name `Windows' does not exist in the namespace `UnityEngine' in Unity 共享指针:Android的“sp &lt;&gt;”模板和BOOST的“shared_ptr &lt;&gt;”模板之间是否存在任何差异? - Shared pointers: are there any gotcha differences between Android's “sp<>” template and BOOST's “shared_ptr<>” template? 错误:“链接”未命名类型 - error: 'link' does not name a type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM