2013-07-15 91 views
3

我想讀取使用c + +和VS2010的sqlite數據庫文件,我寫下面的代碼。如何使用C++讀取sqlite數據。?

sqlite3 *db; 
int rc = sqlite3_open("test.db", &db); 

我得到這樣那樣的錯誤

lib(MSVCR100.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj) 
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj) 
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj) 
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMTD.lib(dbgrealloc.obj) 
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMTD.lib(memmove.obj) 
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.obj) 
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" ([email protected]@[email protected]@@Z) already defined in LIBCMTD.lib(typinfo.obj) 
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" ([email protected]@[email protected]@@Z) already defined in LIBCMTD.lib(typinfo.obj) 
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library 
1>output\win32\Debug\SC.exe : fatal error LNK1169: one or more multiply defined symbols found 

我沒有列入工程sqlite3.lib並給了路..

回答

3

在你的項目,你想同時使用C標準庫的DEBUG版本和RELEASE(NON-DEBUG)版本。

這意味着sqlite3.lib正在使用一種C標準庫,並且您的項目正在使用另一種。您的項目和使用的庫必須匹配調試/發佈選項以及標準庫選項的靜態/動態使用。

+0

@Vaghani可以避免包括'sqlite3.c'而不是'sqlite3.lib'。 –

+0

你的意思是sqlite3.c在附加的依賴關係而不是sqlite3.lib ..? –

+1

否。保留sqlite3.lib。問題是sqlite3.lib依賴於一種C標準庫。爲了能夠在你的項目中使用sqlite3.lib,那麼你的項目必須使用sqlite3.lib使用的相同的C標準庫類型。 –