在将CPP项目编译到.so库时,会产生以下错误:
...
jni/core/src/sqlite3/sqlite3c++.h:26: error: undefined reference to 'sqlite3cpp::database::mp_checkSqliteError(int, std::string)'
jni/core/src/sqlite3/sqlite3c++.h:51: error: undefined reference to 'sqlite3cpp::query::compile()'
jni/core/src/sqlite3/sqlite3c++.h:51: error: undefined reference to 'sqlite3cpp::database::mp_checkSqliteError(int, std::string)'
jni/core/src/sqlite3/sqlite3c++.h:53: error: undefined reference to 'sqlite3cpp::query::compile()'
...
这些文件的位置是:
sqlite3c ++。h :
.....
#include "sqlite3.h"
#ifndef MFDEPSAPI
#define MFDEPSAPI
#endif
namespace sqlite3cpp
{
class MFDEPSAPI database
{
public:
database(std::string databaseFile): mp_transactionInProgress(false), mp_SQLITE_db(0) { if(databaseFile.empty()) return; mp_checkSqliteError(sqlite3_open_v2(databaseFile.c_str(), &mp_SQLITE_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, 0), "opening database"); }
~database();
....
class MFDEPSAPI query
{
public:
query(database& db, const char* strQuery);
~query();
void compile();
....
}
}
sqlite3c ++。cpp 的一部分:
#include "sqlite3.h"
#include "sqlite3c++.h"
#include <iostream>
using namespace std;
namespace sqlite3cpp
{
....
int database::mp_checkSqliteError(int retVal, const std::string description)
{
switch(retVal)
{
case -1:
cerr << "non-typed sqlite library error: " << description << "\n";
return retVal;
break;
case SQLITE_ERROR:
case SQLITE_MISUSE:
case SQLITE_FULL:
case SQLITE_NOMEM:
case SQLITE_INTERRUPT:
case SQLITE_INTERNAL:
case SQLITE_PERM:
case SQLITE_CORRUPT:
case SQLITE_CANTOPEN:
case SQLITE_AUTH:
case SQLITE_RANGE:
case SQLITE_NOTADB:
cerr << "sqlite error: (" << retVal << ") " << sqlite3_errmsg(mp_SQLITE_db) << ", description: \"" << description << "\"" << "\n";
return retVal;
break;
default:
return retVal;
};
}
.....
query::query( database& db, const char* strQuery ) : mp_db(db), mp_isValid(false), mp_strQuery(strQuery), mp_currentIndex(0), mp_SQLITE_statement(0)
{
}
}
通过nkd-build.cmd为这个 Android.mk 安装了cygwin:
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
#### sqlite3
# Here we give our module name and source file(s)
LOCAL_C_INCLUDES := core/src/sqlite3
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := core/src/sqlite3/sqlite3.c
include $(BUILD_STATIC_LIBRARY)
#include $(BUILD_SHARED_LIBRARY)
#### Project
include $(CLEAR_VARS)
LOCAL_MODULE := libgame
LOCAL_CFLAGS := -Wall -Wextra
LOCAL_LDLIBS := -llog -lGLESv2
LOCAL_CPP_FEATURES += exceptions
LOCAL_STATIC_LIBRARIES := libsqlite3
LOCAL_SHARED_LIBRARIES := liblog libGLESv2
# To build the whole .so
FILE_LIST := $(wildcard $(LOCAL_PATH)/core/src/*.cpp)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
INCLUDE_LIST := $(wildcard $(LOCAL_PATH)/core/src/*.h)
LOCAL_C_INCLUDES += $(INCLUDE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_SHARED_LIBRARY)
这可能只是我错过或错误配置的东西。 随意询问是否需要更多文件或其他内容。