我從here下載SQLite的C/C++接口。我得到4個源文件shell.c
,sqlite3.c
,sqlite3.h
和sqlite3ext.h
。如何在XCode的cocos2d-x項目中使用sqlite3
現在我添加所有這些4個文件到我的cocos2d-X項目,並使用下面的代碼測試:
#include "sqlite/sqlite3.h"
sqlite3 *pDB = NULL;
char * errMsg = NULL;
std::string sqlstr;
int result;
result = sqlite3_open("save.db", &pDB);
if(result != SQLITE_OK)
CCLog("failed,status_code:%d ,error_msg:%s\n" , result, errMsg);
sqlite3_close(pDB);
然後我運行它。但它構建失敗,錯誤如下顯示:
duplicate symbol _main in:
/Users/tangyue/Library/Developer/Xcode/DerivedData/CrossKaiser-bkepfijxelboxkchsxvcmpozrwlt/Build/Intermediates/CrossKaiser.build/Debug-iphonesimulator/CrossKaiser.build/Objects-normal/i386/main.o
/Users/tangyue/Library/Developer/Xcode/DerivedData/CrossKaiser-bkepfijxelboxkchsxvcmpozrwlt/Build/Intermediates/CrossKaiser.build/Debug-iphonesimulator/CrossKaiser.build/Objects-normal/i386/shell.o
ld: 1 duplicate symbol for architecture i386 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
我想一定是在這些文件中,出現此錯誤main
。我在文件shell.c
中找到main
方法。因爲我沒有在測試代碼中包含此文件,所以將其從項目中刪除。
然後我再次運行它。這一次,它建立成功,但result
的值是不是SQLITE_OK
,它是14(SQLITE_CANTOPEN
),意思是'無法打開數據庫文件'。
現在該怎麼做才能正確運行程序?什麼是shell.c
文件用於,我是從項目中刪除它是錯誤的。
[更新]
我solove它使用下面的代碼:的
string dbPath = CCFileUtils::sharedFileUtils()->getWriteablePath();
dbPath.append("save.db");
CCLog("%s", dbPath.c_str());
result = sqlite3_open_v2(dbPath.c_str(), &pDB, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
代替
result = sqlite3_open("save.db", &pDB);
感謝你的幫助的第二部分,我在尋找正確的文件路徑一些工作之後,我的問題是soloved。 – pktangyue 2013-02-18 07:47:54