0

I'm working with a cocos2dx c++ android project that I compile with Eclipse (java edition). Everything has worked great until I try to use 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'"

"undefined reference to 'sqlite3_open'"

I had a similar problem with the win32 build and that was solved by adding the sqlite library in Visual Studio. Guess it's the similar problem now but I have no idea how to solve that in Eclipse?

GLADIATORCOP
  • 49
  • 1
  • 6

1 Answers1

0

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.

My Android.mk do now look like this.

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.

GLADIATORCOP
  • 49
  • 1
  • 6