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

允我心安 提交于 2019-11-30 23:15:22

最近使用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_static

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!