How can I resolve "error LNK2019: unresolved external symbol"?
Solution 1
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...
Solution 2
I know it is already 2 years since this question... but i run in the same situation here. Added all the header files... added the lib directories.. and keep having this error. So i added manually the lib to the Configuration Properties -> Linker -> Input -> Aditional Dependencies and all works for me.
Solution 3
Don't know if it is your case, but the imp prefix may mean that you are compiling a x64 library in a Win32 project.
Solution 4
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 ?)
Solution 5
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.
Attilah
Updated on September 17, 2020Comments
-
Attilah over 3 years
I've got this MFC application I'm working on that needs to have an embedded database. So I went hunting for a slick, fast "embeddable" database for it and stumbled accross SQLite.
I created a DB with it, and I created a static library project with Visual Studio 2008. the library project will be used in another main project.
In the library project, I created a class
DBClass
with a methodAddFeedToDB(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?
-
Attilah almost 15 yearsin the library project, i went to project->properties->Configuration Properties->Librarian->General->Additional Dependencies and I added "..\SQLiteCommon\sqlite3.lib" to it.
-
MickaelFM almost 15 yearsDid you link it statically (as you compiled it) ?
-
Attilah almost 15 yearsyes, 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 almost 15 yearsthe 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.
-
ST3 over 10 yearsDoes this answers into given question?
-
xtofl over 10 years@ST3: apparently, it solved this particular case. It's not a general recipe for solving linker errors, if that's what you mean.
-
Milind Morey about 10 yearsGreat,Thanks for good answer,linker error is due to dependancy
-
mr_T over 9 yearsYes, adding this line solved my (similar) problem too. What is actually happen is that some project needs a symbol defined in another dll which is not exported (typically MSVS)