问题
I'm working in a Cocos2dx (c++) win 32 project and trying to use sqlite to save the game data. My knowledge of c++ / Visual Studio is very limited right now.
This is part of the code that I'm trying to compile.
#include <sqlite3\include\sqlite3.h>
...
void HelloWorld::SaveAndLoadTest()
{
sqlite3 *pdb = NULL;
sqlite3_open("writablePath", &pdb);
...
}
But when I try to compile the line with the sqlite3_open command I get the following error:
Error 7 error LNK2019: unresolved external symbol _sqlite3_open referenced in function...
I've been trying to find an answer for this many hours. The most similar question I found was this one but I don't understand the answer. Error: undefined reference to `sqlite3_open'
You need to link the sqlite3 library along with your program:
g++ main.cpp -lsqlite3
I'm new to Visual Studio and I don't understand how to solve this, anyone?
回答1:
The error LNK2019 means that references are missing probably because a library is mising.
To add sqlite to a MSVC project, you have to make sure that:
- the header is included in your source files
sqlite3.dll
is in the path or in the directory of the executable- AND that
sqlite3.lib
is added to the additional dependencies in the VS project (options of the project > Linker > Input > Additional dependencies)
This last point is mandatory, because the lib tells the linker which functions are stored in the dll.
回答2:
The solution, quite simply, is to link sqlite3
to your project. Libraries need to be linked (via the linker) for you to be able to use them. Head over here and download the pre-compiled binaries for your platform of choice (in this case, Win32). You may also choose to compile sqlite3
from source. You should end up with a .lib
file. Go to Project -> Configuration Properties -> Linker -> General -> Additional Include Directories
and add the path to your library file to it. Then go to Linker -> Input -> Additional Dependencies
and put in sqlite3.lib
.
来源:https://stackoverflow.com/questions/28776898/error-when-trying-to-compile-using-sqlite3-open-in-visual-studio-2013