Baba
Baba

Reputation: 151

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?

Upvotes: 7

Views: 8879

Answers (2)

Warpspace
Warpspace

Reputation: 3448

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.

Upvotes: 11

Colen
Colen

Reputation: 13908

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

Upvotes: 0

Related Questions