Cygwin gcc cannot find the stdlibc++ files

Put problems with the Android NDK in this forum.

Cygwin gcc cannot find the stdlibc++ files

Postby lucafr » Wed Sep 07, 2011 10:27 pm

I am playing with android ndk. I am using Window Vista with cygwin (latest version). I compiled and launched the hello world jni sample on my phone. It is working. The code is (is a .cpp file):


#include <string.h>
#include <jni.h>

extern "C" {
JNIEXPORT jstring JNICALL Java_org_android_helloworld_HelloworldActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis);
};


jstring Java_org_android_helloworld_HelloworldActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis)
{
return env->NewStringUTF("Hello from native code!");
}

I wanted to add some modifications, just to play with it a bit:

#include <algorithm>

and then, in the function above, i added:

int a;
a=std::min<int>(10, 5);


but the compiler says that it cannot find the file 'algorithm' and that min() is not part of std.

After a bit of searching, i have found that the android ndk has a gnu-libstdc++ directory with all the std files needed. Reading the NDK docs, i have learned that usint std::* should work without any modification to the code (if one include the proper header files). But it seems that gcc on cygwin is not able to find the needed files.

What are the steps to do in order to be able to use std and stl within a .cpp file in an android ndk app?

Thx
lucafr
Freshman
Freshman
 
Posts: 2
Joined: Wed Sep 07, 2011 10:21 pm

Top

Re: Cygwin gcc cannot find the stdlibc++ files

Postby lucafr » Thu Sep 08, 2011 10:50 am

Ok, i found the problem. First, by default, the headers and libraries for the minimal C++ runtime system library (/system/lib/libstdc++.so) are used when building C++ sources. If you want to use all the features of STL, you need to create (or edit if already exist) a file called Application.mk under /jni directory of your project. Add there the line:

APP_STL := stlport_static

Now, you can include and use STL as you wish. Probably, the first time you compile your project gcc will re-compile STL (i am still investigating how to avoid this).

My original error was probably due to late-night coding: i was editing Android.mk instead of Application.mk!!
lucafr
Freshman
Freshman
 
Posts: 2
Joined: Wed Sep 07, 2011 10:21 pm

Re: Cygwin gcc cannot find the stdlibc++ files

Postby jonbonazza » Fri Sep 09, 2011 1:46 am

The build of STLPort that is available from Google using the method you spoke of is still not complete. Some pretty major components are still missing (most notably the exceptions class).

There is, however a clever guy that goes by the handle Crystax who provides an alternate version of the NDK with full STL support. You can get it here:
http://www.crystax.net/android/ndk.php

He releases an updated version about a month or so after every official Google update, so he's pretty reliable.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to NDK Problems

Who is online

Users browsing this forum: No registered users and 3 guests