Reputation: 82
I cannot figure out how to get sqlite3.dll (or any dll for that matter) to work with my C++ project in Visual Studio.
The error message I get is LNK2001 unresolved external symbol sqlite3_open
Here's what I did so far:
lib /def:sqlite3.def
(pretty much followed the instructions seen here)
Thank you for help
Upvotes: 0
Views: 1678
Reputation: 6427
It's difficult to tell exactly why the problem occurred. There are lots of reasons which could cause LNK2001
error. MSDN contains good check list.
You could try to use /VERBOSE
option to determine which files the linker references. Put this option in Project -> Preferences -> Linker -> Command Line -> Additional Options
. Output should contains similar strings:
Searching e:\SQLite\sqlite-dll-win32-x86-3150100\sqlite3.lib:
Found _sqlite3_open
Referenced in ConsoleApplication2.obj
Loaded sqlite3.lib(sqlite3.dll)
Pay attention to the VS runtime libraries, there should be no mixup between Debug and Release libraries.
Upvotes: 0
Reputation: 146
The issue is that by default the header file assumes that sqlite is linked statically, as opposed to dynamic linking to a dll.
This part of sqlite3.h is responsible for that:
#ifndef SQLITE_API
# define SQLITE_API
#endif
If you set a per-project define in project properties:
SQLITE_API=__declspec(dllimport)
this should resolve your link error. Alternatively, you can put
#define SQLITE_API __declspec(dllimport)
right before where you #include sqlite3.h.
Upvotes: 4