0

I searched how to use to_string() in android ndk. After a long search, from this link, i changed the Application.mk file as said. And the cpp source compiled and build properly only from the terminal.

        Terminal output :
         > ndk-build
        Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 9 in        
/<some path>/Android/Exercise01/AndroidManifest.xml    
    [armeabi-v7a] Install        : libndkfoo.so => libs/armeabi/libndkfoo.so

But in ecplise IDE, still i am getting error as "Function 'to_string' could not be resolved". So from the IDE i am not able to run the android application. (Note : before the usage of std::to_string, the source compiled properly)

I tried to include the header files as below (under project properties->C/C++ general->Path and Symbols->GNU C++)

vstring.h from //android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.9/include/ext
&
basic_string.h from //android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.9/include/bits

But no luck.

Androi.mk File

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS    := -llog
TARGET_PLATFORM := android-21
TARGET_ARCH_ABI := armeabi-v7a
TARGET_ABI := android-21-armeabi-v7a # concatenation of above two variables
# Here we give our module name and source file(s)
LOCAL_MODULE    := ndkfoo
LOCAL_C_INCLUDES := $(LOCAL_PATH)/header
LOCAL_SRC_FILES := src/NativeFunction.cpp src/clsArithmeticParser.cpp
include $(BUILD_SHARED_LIBRARY)

Application.mk

#APP_STL := stlport_static
APP_STL:=c++_static       

I know, i am doing some small mistake, but not able to find for a long time. Any solution/suggestion appreciated.

Edited :
I am able use the std::to_string & std::stoll through eclipse in the below trick only. These can help some one in rare situation. So adding this point to test the c++11 support through eclipse IDE. The error shown only when the source file or the header file opened. Just close open source file documents (.h, .c, .cpp). Close and reopen the eclipse. Now it is ready to compile and run through the android emulator.

Community
  • 1
  • 1
Jeet
  • 1,006
  • 1
  • 14
  • 25
  • Why do you have multiple `APP_STL`-assignments in Application.mk? And why are you trying to include "basic_string.h" instead of `#include `? – Michael Mar 22 '16 at 16:25
  • @Michael, the #include already there. Still showing the error. After the addition of the "APP_STL:=c++_shared" the std::to_string() got recognized and compile & build through terminal. – Jeet Mar 22 '16 at 16:33
  • @Michael, i excluded the "APP_STL := stlport_static" and the source getting compiled in terminal as previously. Still the eclipse IDE showing the error. – Jeet Mar 22 '16 at 16:37
  • Have you tried rebuilding the index in Eclipse? – Michael Mar 22 '16 at 16:40
  • @Michael, yes multiple times. But no luck. – Jeet Mar 22 '16 at 16:41
  • @Michael, this is for your information that I am able to use std::string(::append) & std::vector(::at) properly through eclipse.(before using to_string) – Jeet Mar 22 '16 at 16:55

2 Answers2

1

What version of Eclipse IDE do you use? Try to update to the latest Mars version, it may fix your problem.

khaledev
  • 496
  • 4
  • 6
  • after latest eclipse installation...also no luck. – Jeet Mar 22 '16 at 19:45
  • 1
    **+1 It works.......** It worked after updating latest version & referring this [link](http://stackoverflow.com/questions/16786555/eclipse-compiles-successfully-but-still-gives-semantic-errors/16891713#16891713). In my case only the **"Run with build is checked"**. Close and reopen IDE & Index->Rebuild – Jeet Mar 23 '16 at 08:37
  • Great to hear it worked for you! Thanks for sharing with us your solution. – khaledev Mar 23 '16 at 10:40
1

After referring the answer by @Khaled Lakehal, I myself posting this answer for my question.Hope this may help someone.

Followed the below step to make it work:

  1. Update the eclipse version from Luna to latest Mars 2
  2. Imported the existing project from the old version of the eclipse using -> import -> Existing Android code into Workspace
  3. Had some problem with the C/C++ project conversion after import. So followed this link to undo the C/C++ project conversion
  4. Converted the project to C/C++ newly.
  5. To remove the error, I referred this link, and selected the "Run with build" only
  6. Close & Reopen the IDE

So now able to use the std::to_string & std::stoll functions.

Community
  • 1
  • 1
Jeet
  • 1,006
  • 1
  • 14
  • 25