android - 在 Windows 中为 Android 编译 .cpp 文件

标签 android c++

我有一个用代码块编写的名为 main.cpp 的 cpp 文件。我想在 windows 10 64bit 中为 android 编译它。

#include <iostream>
#include <cmath> 
using namespace std;



#define greater(x,y) (x<y?y:x);

int main(){


int a,b;
cout<<"Enter two numbers "<<endl;
cin>>a>>b;
cout<< "The greater number is "<<greater(a,b);

}

我使用适用于 windows 的 android ndk 工具链。我打开 cmd 并使用了这个命令。

x86_64-linux-android-gcc.exe main.cpp -o main.

我面临的错误..

 fatal error: iostream: No such file or directory
  #include <iostream>
                ^
compilation terminated. 

我想我做错了程序。

编辑: 我找到了答案。

来源:http://tricksfairbd.blogspot.com/2018/05/compile-cpp-code-for-android-in-windows.html

最佳答案

您必须告诉 gradle 包含必需的库,以便可以使用它们进行编译。

build.gradle 中,您应该包含类似于以下内容的内容:

android.ndk {
    moduleName = "hello-jni"
    stl        = "stlport_static"
}

来源:Can not include iostream in Android NDK

关于android - 在 Windows 中为 Android 编译 .cpp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50573546/

相关文章:

c++ - 如何通过鼠标移动使OpenGL相机在SFML中移动

c++ - 此哈希仅适用于枚举类型

android - 有没有自动化测试工具来测试android apk?

android - * native react * |使用未知 URL 链接 => canOpenURL(url)?

安卓。文本输入布局。切换密码可见性事件监听器?

c++ - vector 初始化

android - 如何在 RxJava2 中等待 Maybe 项列表完成?

android - 当标记以 "IMS"开头时,为什么 Logcat 不打印日志?

c++ - Sprite::createWithTexture with Rect 未按预期工作

c++ - 结构的大小超过预期