简体   繁体   中英

Problem to build NDK with C++ in Android

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM