开发者

Problem to build NDK with C++ in Android

开发者 https://www.devze.com 2023-02-14 02:03 出处:网络
Currently I am working with the Android NDK and JNI. I am trying to build a C++ code with NDK. But I got the following errors:

Currently I am working with the Android NDK and JNI. I am trying to build a C++ code with NDK.

But I got the following errors:

E:/Android/Tranining_workspace/开发者_开发技巧BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:10:19: error: fstream: No such file or directory
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:20: error: 'ifstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:21: error: 'ofstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:22: error: 'ofstream' does not name a type
E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:34: error: 'string' was not declared in this scope                 

Can anyone please help me out?


I just encountered the same problem. Seems the STL is not automatically included in NDK projects by default. That also means iostream, fstream, string etc can't be used straight away. To enable them, you'll need to modify your Application.mk file. If you don't have one (it's in the <project>/jni directory), then just create a new, blank one. Add the line:

APP_STL := stlport_static

Also, also remember to include using namespace std; or equivalent, along with the usual #include <iostream> etc.


Did you remember your:

#include <iostream>
using namespace std;

definitions at the top of the file?

("using namespace std" isn't always a good idea, but that's a separate issue.)

0

精彩评论

暂无评论...
验证码 换一张
取 消