[英]How to add a sqlite library in Eclipse java edition?
I'm working with a cocos2dx c++ android project that I compile with Eclipse (java edition). 我正在使用我用Eclipse编译的cocos2dx c ++ android项目(java版)。 Everything has worked great until I try to use sqlite3.
一切都运行良好,直到我尝试使用sqlite3。
I'm pretty sure the code is correct. 我很确定代码是正确的。
sqlite3 *pdb = NULL;
int result;
std::string path = FileUtils::getInstance()->getWritablePath();
path.append("mydb.db");
FILE* file = fopen(path.c_str(), "r");
if (file == nullptr) {
CCLOG("no such file");
long size = 0;
const char* data = (char*) FileUtils::getInstance()->getFileData("mydb.db", "rb", &size);
file = fopen(path.c_str(), "wb");
fwrite(data, size, 1, file);
CC_SAFE_DELETE_ARRAY(data);
}
result = sqlite3_open(path.c_str(),&pdb);
if (result != SQLITE_OK)
CCLOG("OPEN FAILED");
else
CCLOG("OPEN WORKED");
char **re;
int r,c;
sqlite3_get_table(pdb,"select * from mytable", &re, &r, &c, NULL);
CCLOG("num of rows is %d, num of columns is %d", r, c);
I get these errors 我收到这些错误
"undefined reference to 'sqlite3_get_table'" “对'sqlite3_get_table'的未定义引用”
"undefined reference to 'sqlite3_open'" “对'sqlite3_open'的未定义引用”
I had a similar problem with the win32 build and that was solved by adding the sqlite library in Visual Studio. 我在win32版本中遇到了类似的问题,这是通过在Visual Studio中添加sqlite库来解决的。 Guess it's the similar problem now but I have no idea how to solve that in Eclipse?
猜猜现在是类似的问题,但我不知道如何在Eclipse中解决这个问题?
Thanks for the help sithereal. 谢谢你的帮助。 Not sure what was wrong in my Android.mk file but I wiped out the file and used another template that solved the problem.
不知道我的Android.mk文件有什么问题,但是我删除了文件并使用了另一个解决问题的模板。
My Android.mk do now look like this. 我的Android.mk现在看起来像这样。
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/x.cpp \
../../Classes/y.cpp \
../../Classes/HelloWorldScene.cpp\
../../Classes/sqlite3.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
And everything is working fine. 一切都很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.