Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'std::string' could not be resolved.

I'd started porting some Java code in native c++ in Android. I have an issue with using strings in c++:

Type 'std::string' could not be resolved

There is my sample code

#include <jni.h>
#include <lexu_me_test_native.h>
#include <string.h>
using namespace std;

JNIEXPORT jstring JNICALL Java_lexu_me_test_native_prepairToShowNative
  (JNIEnv * env, jclass javaThis, jstring str)
{
    jboolean blnIsCopy;
    jstring jstrOutput;
    char* strCOut;
    std::string ss;

    const char* strCIn = (env)->GetStringUTFChars(str , &blnIsCopy);
    // convert jstring to a char array
    // Do stuff with the char array and and store the result
    // in another char array strCOut
    (env)->ReleaseStringUTFChars(str , strCIn); // release jstring

    jstrOutput = (env)->NewStringUTF(strCOut); // convert char array to jstring
    return jstrOutput;
}

Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := native
LOCAL_SRC_FILES := native.cpp

include $(BUILD_SHARED_LIBRARY)

Application.mk file:

APP_STL := stlport_static

MinGW installed and added to path. I tried using android-ndk-r8e and android-ndk-r8-crystax-1 nothing helped. In Cygwin Terminal errors:

Compile++ thumb  : native <= native.cpp
jni/native.cpp: In function '_jstring* Java_lexu_me_test_native_prepairToShowNative(JNIEnv*, jclass, jstring)':
jni/native.cpp:11:2: error: 'string' was not declared in this scope
jni/native.cpp:11:9: error: expected ';' before 'ss'

I'm using Win 7 64bit. Can anyone say how it could be solved? Thanks.

EDIT.

In C/C++ General - Path and Symbols already set: C:\Android\android-ndk-r8e\platforms\android-14\arch-arm\usr\include

like image 212
LEX Avatar asked Aug 02 '26 10:08

LEX


1 Answers

If the other answers didn't work, then try these steps:

  1. If you have using namespace std;, use string instead of std::string.
  2. If #include <string> doesn't work and you're using Linux, try #include <unistd.h>. If you're using another OS, use #include <cstdlib>.
like image 66
Ldddd Avatar answered Aug 03 '26 23:08

Ldddd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!