android - JNI中写原生c++代码编译,各种 error: ’xxx’ does not name a type?

【字号: 日期:2022-12-08浏览:32作者:雯心

问题描述

本人小白,以前是做Android的,现在刚开始做ndk开发,就我一人,使用的是studio,现在一般的java和c++之间的调用和传参没什么问题,但是现在在做的是一个人脸识别的项目,公司使用的是c++写的代码,c++代码很多,然后使用让我使用jni进行调用里面的方法,但是面临一个头疼的问题,就是,写好头文件之后,现在在拷贝他们的c++代码进来,除了调用的几个函数实现的时候用的是JNI的方式,其他的函数都是用的原生的c++代码,结果报了很多错误,先是头文件的错误,include<io.h>,<windows.h>都不行,后来和老大协商一下,改了一些代码,头文件不报错了,但是现在定义的全局变量,在编译的时候报了很多很多类似error: ’map’ does not name a type,error: ’vector’ does not name a type的错误,还有很多error: ’cout’ was not declared in this scope的这种错误,由于对c++不熟悉,所以现在特别头疼,希望各位大神指点一二,江湖救急啊!!都是报的是原生C++中的错误

我已经在全局进行声明了

map<int, string> g_id2name;map<int, int> g_id2line;int g_numKeypoints = 0; int g_numObjects = 0; CvMemStorage* g_storageObj;vector<int> g_labels; vector<int> g_laplacians;CvSeq *g_dbKeypoints = 0;CvMat* g_objMat;int g_curObject = 0; int g_matchFileStatus = 0;char* g_matchFileName = 0;

还是报了很多下面这种错误

Error:(48, 1) error: ’map’ does not name a typeError:(53, 1) error: ’vector’ does not name a typeError:(94, 5) error: ’ifstream’ was not declared in this scopeError:(131, 9) error: ’cerr’ was not declared in this scopeError:(158, 5) error: ’cout’ was not declared in this scopeError:(160, 25) error: invalid operands of types ’int’ and ’const char [2]’ to binary ’operator<<’Error:(536, 46) error: ’g_id2name’ was not declared in this scope 。。。。。。

问题解答

回答1:

#include <map>#include <vector>//etcusing namespace std;

回答2:

推荐用C,用Cpp的话,so会比较大,因为需要把Cpp的STL库打包进来

相关文章: