25

I am trying to compile an android application in android studio (ndk r10d) which uses some C++ code. I needed C++11 so I added -std=gnu++11 (I need gnu++11 instead of c++11 for an extension I am using). I am using the stlport stl, due to other libraries I am using that use this stl library. So my cFlags and stl parameters in the build.gradle file looks like this:

stl "stlport_static"
cFlags " mylib1.a mylib2.a ... -fexceptions -frtti -std=gnu++11"

I also have included 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.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
royeet
  • 829
  • 1
  • 9
  • 12
  • What's the actual code that causes the error? – Kerrek SB Mar 07 '15 at 12:24
  • The original error is on this define I added to make code shorter but the errors are seen throughout the files wherever I try to use this macro: #define myapp_shared_ptr std::shared_ptr – royeet Mar 07 '15 at 16:33
  • shared_ptr doesn't name a type. It names a type template. Are you sure you're doing shared_ptr when you use it? The error I get when I leave that out is "use of class template requires template arguments" – Charlie Mar 08 '15 at 03:42
  • I don't think STLport has C++11 features. – T.C. Mar 08 '15 at 06:38

3 Answers3

44

http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared use head file in your code.

#include <memory>
CantrianBear
  • 1,013
  • 1
  • 12
  • 22
MYLOGOS
  • 621
  • 5
  • 6
2

@T.C Looks like you were right. 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.

What I think happened is that the libraries I'm using are not using any C++11 features that the STLport is missing. They are only using C++11 features that the gcc compiler supports. I need the gnuStl to support the features that I am using.

My solution was to use the boost implementation for the smart pointers and all other missing C++11 features.

royeet
  • 829
  • 1
  • 9
  • 12
1

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
miravalls
  • 365
  • 1
  • 7