Saturday 31 March 2018

c++ - How can I resolve "error LNK2019: unresolved external symbol"?




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 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?


Answer



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...


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...