My develop environment is : Windows7 + eclsipse + ADT + CDT + NDK (latest version)
The head file code:
#ifndef HEAD_H_
#define HEAD_H_
#ifdef HAVE_INLINE
# if defined(__GNUC_STDC_INLINE__) || defined(GSL_C99_INLINE) || defined(HAVE_C99_INLINE)
# define INLINE_DECL inline /* use C99 inline */
# define INLINE_FUN inline
# else /*the part real work, since I have define HAVE_INLINE */
# define INLINE_DECL /* use GNU extern inline */
# define INLINE_FUN extern inline
# endif
#else
# define INLINE_DECL /* */
#endif
extern "C" {
INLINE_DECL double add(int x, int y);
#ifdef HAVE_INLINE
INLINE_FUN double add(int x, int y) {
return x+y;
}
#endif
extern inline double ad(int x, int y) {
return x-y;
}
}
#endif /* HEAD_H_ */
The cpp file is :
#include <jni.h>
#include <android/log.h>
#include <head.h>
#include <string.h>
#include <iostream>
#include <sstream>
#define LOG_TAG "OCV:libnative_activity"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#ifdef __cplusplus
extern "C" {
#endif
jstring
Java_com_igit_testcinline_MainActivity_main(JNIEnv* env, jobject thiz){
double c = add(1,2); /*Error, undefined reference to 'add'*/
double d = ad(2,1);
.....
When I use NDK make, the error "undefined reference to 'add' " will occur in cpp file. I don't know why the error occur, but the function ad() work well.