views:

4005

answers:

4

I've got this MFC application i'm working on that needs to have an embedded database. so, i went on hunting for a slick,fast "embeddable" db 4 it and stumbled accross SQLite.

now, i've created a DB with it, and i created a static library project with VS2k8.the library project will be used in another main project .

in the library project, i created a class 'DBClass' with a method : AddFeedToDB(CFeed f). the library project uses

the .lib file from codeproject (cppsqlite3.lib).

when compiling the static library, no error is detected but when i try to use the library project file in the main

project, i get these type of errors :

"error LNK2019: unresolved external symbol 
   "public:void __thiscall CppSQLite3DB::close(void)"
   (?close@CppSQLite3DB@@QAEXXZ 
   referenced in function "public: int __thiscall
   CTalkingFeedsDB::AddFeedToDB(class CFeed,char const*)"(?
   AddFeedToDB@CTalkingFeedsDB@@QAEHVCFeed@@PDB@Z"

what am i missing ?

+1  A: 

You either need to link the codeproject SQLite lib to your executable, or to include the sources files in your project directly. (Which one did you do ?)

MickTaiwan
in the library project, i went to project->properties->Configuration Properties->Librarian->General->Additional Dependencies and I added "..\SQLiteCommon\sqlite3.lib" to it.
Attilah
Did you link it statically (as you compiled it) ?
MickTaiwan
yes, i linked it statically, i think. but wht's weird is that as in other project types, i don't see a Linker tab in Project Properties->Configuration properties, but i see Librarian instead.
Attilah
A: 

I would follow these steps:

  1. think about what library or .obj file you expect the symbol to be exported by.

  2. check whether it actually does export that very symbol (check character-wise). Sometimes, it's the calling convention differs.

  3. check if the library you expect to contain the symbol is known to the linker - first check for the 'additional libraries', then check if the library is actually found (I mostly do this by using filemon.exe from sysinternals, and look for link.exe to open the lib file. )

After thinking a while, you may find that your library project will not export the sought for function. That function is in the database lib. You should add that lib to your main project. It's no use adding it to your static lib project.

xtofl
the lib(sqlite.lib) does export the symbols.i added the lib to my main project, still it doesn't work. i still get the same errors.
Attilah
A: 

It happened to me more than once that I thought symbol XXX (i.e. ?close@CppSQLite3DB@@QAEXXZ) was in the import lib, while the actual symbol was __impXXX (i.e. __imp?close@CppSQLite3DB@@QAEXXZ).

The reason for the linker error is then to be found in the compilation step: the compiler will generate the ?close@CppSQLite3DB@@QAEXXZ symbol to be imported, where it should generate __imp?close@CppSQLite3DB@@QAEXXZ. This often means that the function declaration itself didn't have __declspec( dllimport ). Which may be caused by some preprocessor symbol not being defined. Or the __declspec not being there at all...

xtofl
+1  A: 

The compiler and linker will not link one library into another (unless one is a DLL). You need to specify both libraries (cppsqlite3.lib and your own static library) in your main project.

Mark Ransom