Android NDK 'std::string' has not been declared

最近使用NDK, 在C++頭文件中加入
#include <string>

ndk-build後報錯
x.h: fatal error: string: No such file or directory

試着換成
#include <string.h>
ndk-build後繼續報錯
x.h: error: 'std::string' has not been declared

真是鬱悶, 後來在網上搜索了一大圈, 原來是須要讓Android NDK支持STL
Import STL libraries to the Android NDK code
> This is a quick tip for those who are beginning to write native Android code.
> As one may have noticed, it isn’t possible to use containers like, string, vector, list inside the NDK samples.
> These are all part of the STL (Standard Template Library), and are expected to be available when writing C++ code.
> The Application.mk, works similarly as the Android manifest file for your NDK code,
> allowing the programmer to add permissions and define other applications' properties, like such as 'enabling' the STL support.

將Application.mk放在jni目錄下(內容以下)
APP_STL := stlport_staticandroid

相關文章
相關標籤/搜索