2012-05-16 65 views
0

我正在嘗試編寫SQLite的包裝類,通過隱式鏈接通過DLL公開,即生成庫和頭文件供消費者編譯和鏈接。隱式DLL鏈接和類內部函數

目前我正在導出包裝類,但是當我嘗試編譯使用此包裝類的項目時,我收到了無法解析sqlite API調用的鏈接器錯誤,例如, sqlite3_open。包裝類和消費者都是C++,但是sqlite是C.

爲什麼消費者需要知道不暴露給它的函數(包裝類的整個點)?這是否意味着我需要修改SQLite頭以更改其函數,以便爲所有函數/我要封裝的函數提供適當的_declspec(dllexport)裝飾?這種改變是否有其他選擇?

的鏈接器錯誤:

libsqlite.lib(sqlitewrapper.oxl) : error LNK2019: unresolved external symbol _sq 
lite3_close referenced in function "public: virtual __thiscall CSQLiteWrapper::~ 
CSQLiteWrapper(void)" ([email protected]@[email protected]) 

libsqlite.lib(sqlitewrapper.oxl) : error LNK2019: unresolved external symbol _sq 
lite3_open referenced in function "public: __thiscall CSQLiteWrapper::CSQLiteWra 
pper(class ATL::CStringT<char,class ATL::StrTraitATL<char,class ATL::ChTraitsCRT 
<char> > > const &)" ([email protected]@[email protected][email protected][email protected]?$C 
[email protected]@[email protected]@@[email protected]@@[email protected]@@Z) 

libsqlite.lib(sqlitewrapper.oxl) : error LNK2019: unresolved external symbol _sq 
lite3_free referenced in function "public: virtual void __thiscall CSQLiteWrappe 
r::Exec(class ATL::CStringT<char,class ATL::StrTraitATL<char,class ATL::ChTraits 
CRT<char> > > const &,int (__cdecl*)(void *,int,char * *,char * *))" ([email protected] 
[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@@[email protected] 
@[email protected]@Z) 

libsqlite.lib(sqlitewrapper.oxl) : error LNK2019: unresolved external symbol _sq 
lite3_exec referenced in function "public: virtual void __thiscall CSQLiteWrappe 
r::Exec(class ATL::CStringT<char,class ATL::StrTraitATL<char,class ATL::ChTraits 
CRT<char> > > const &,int (__cdecl*)(void *,int,char * *,char * *))" ([email protected] 
[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@@[email protected] 
@[email protected]@Z) 

回答

1

我的問題的根本原因是我使用「lib」命令來生成我然後鏈接的庫。正如Ixop提到的那樣,在這種情況下,我需要確保SQLite被添加到我的庫中,即使它不直接暴露在DLL中。

但是,通過隱式鏈接,我應該一直在使用IMPLIB鏈接器指令來生成庫。對此進行修改以解決問題。

2

你有靜態鏈接你對SQLite的庫包裝?這樣做意味着所有的東西都存在於你的庫中,而不僅僅是一個網關,所以鏈接器錯誤應該消失。這是假設你不想讓SQLite庫與你的包裝器分開。

+0

+1,這將是一個解決方案,但不是我正在尋找的解決方案,因爲它不會是隱式鏈接解決方案。 – dlanod