您的位置:首页 > 移动开发 > Android开发

Android NDK 编译出现 string:No such file or directory

2016-12-23 13:33 411 查看


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


 U_U 2013-02-03
22:02:38

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

头文件中#include <string>就OK了, 注意使用std::string或加上using namespace std;

#include <string>

using namespace std;

class X {

    public:

    void a(string);

    void b(std::string);

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android #include string
相关文章推荐