gpt4 book ai didi

android - 为什么无法在 android 中包含 iostream?

转载 作者:可可西里 更新时间:2023-11-01 17:32:47 26 4
gpt4 key购买 nike

已安装android-ndk-r7,正在尝试编译.cpp文件。

#include <iostream>

using namespace std;

int main ( int argc, char ** argv)
{

cout <<"Hello World.."<<endl;

}

执行了以下命令:进入jni文件夹,执行

#ndk-build

出现以下错误:

/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:1:20: error: iostream: No such file or directory
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp: In function 'int main(int, char**)':
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:8: error: 'cout' was not declared in this scope
/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/jni/test1.cpp:8: error: 'endl' was not declared in this scope
make: *** [/home/jelari/Desktop/androidDevelopment/android-ndk-r7/DCF/obj/local/armeabi/objs/test1/test1.o] Error 1

我做错了什么?

我的 Android.mk 文件如下所示:

# A simple test for the minimal standard C++ library
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := test1
LOCAL_SRC_FILES := test1.cpp
include $(BUILD_EXECUTABLE)

Application.mk 文件如下所示:

# Build both ARMv5TE and ARMv7-A machine code.
APP_ABI := armeabi armeabi-v7a

请指出错误?

最佳答案

只是为了在 SO 上很容易找到答案,这里是:

By default, the C++ standard library is very minimal.

You need to set APP_STL in your Application.mk file.

I use:

APP_STL := gnustl_static

but you could have used system, stlport_static, stlport_shared, or gnustl_static.

It's documented under $NDK/docs/CPLUSPLUS-SUPPORT.html, and it's a little hidden, because the $NDK/documentation.html index file doesn't list it.

引自http://groups.google.com/group/android-ndk/browse_thread/thread/983c436239d48704?pli=1

关于android - 为什么无法在 android 中包含 iostream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com