How to use native CPP functions and libraries in cocos2dx ??


#1

that other day i had an error (and i am still stuck on that) about this “std::” thing.

As any CPP programmer you can recognise its the standard namespace;

I had used the following code :

std::random_shuffle(_grid.begin(),_grid.end());

And that gave me the error that “random_shuffle is not a member of std”

I searched for the error and came across this[[http://www.cocos2d-x.org/forums/18/topics/30601]] page.
In one of the replies, there is a mention that we have to import some CPP libraries separately in the project. Now i dont know from where we have to import those libraries.

For example the reply suggest this path…
\ /sources/cxx-stl/gnu-libstdc*/include
\ /sources/cxx-stl/gnu-libstdc+/libs/armeabi-v7a/include

but i dont know the “sources” address…


#2

Are you 100% sure that you have all the includes needed? (#include < algorithm >)
On which platform and IDE are you working on? What which compiler?


#3

i am on linux 64-bit, using cocos2d-2.0-x-2.0.4 , using android ndk-r8b… using eclipse indigo…and having following includes in my project…

cocos2dx/cocos2d-2.0-rc2-x-2.0.1/cocos2dx/include

android-ndk/android-ndk-r8b/platforms/android-9/arch-arm/usr/include


#4

thanks man…

#include <algorithm>

did the trick…hopefully for now !!!


#5

Ram Mehta wrote:

thanks man…

#include <algorithm>

did the trick…hopefully for now !!!

Just check where the used function/containers come from.

_grid

Underscore is reserved for the standard library and compiler vendors (exact rules below), so avoid using it at all. (Though, it’s legal to start a variable with underscore and small letter not in global scope):

17.4.3.2.1 Global names [lib.global.names]

Certain sets of names and function signatures are always reserved to the implementation:

Each name that contains a double underscore (_ _) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.165
165) Such names are also reserved in namespace ::std (17.4.3.1).

7.1.3 Reserved identifiers

Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.

All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
Each macro name in any of the following subclauses (including the future library directions) is reserved for use as specified if any of its associated headers is included; unless explicitly stated otherwise (see 7.1.4).
All identifiers with external linkage in any of the following subclauses (including the future library directions) are always reserved for use as identifiers with external linkage.154
Each identifier with file scope listed in any of the following subclauses (including the future library directions) is reserved for use as a macro name and as an identifier with file scope in the same name space if any of its associated headers is included.
No other identifiers are reserved. If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.

If the program removes (with #undef) any macro definition of an identifier in the first group listed above, the behavior is undefined.

  1. The list of reserved identifiers with external linkage includes errno, math_errhandling, setjmp, and va_end.