简体   繁体   中英

Microsoft Visual Studio C++ 2013 Linking Error (when using SQLite wrapper)

Here is my main loop:

#include <string>
#include <stdio.h>
#include <iostream>
#include <sqlite3.h>


using namespace std;

int main()
{
    sqlite3 *database;
    sqlite3_open("db.sql", &database);

    return 0;
}

When I compile it, it throws a linking error. Errors are as follow:

1>Students.obj : error LNK2028: unresolved token (0A000451) "extern "C" int __cdecl sqlite3_open(char const *,struct sqlite3 * *)" (?sqlite3_open@@$$J0YAHPBDPAPAUsqlite3@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Students.obj : error LNK2019: unresolved external symbol "extern "C" int __cdecl sqlite3_open(char const *,struct sqlite3 * *)" (?sqlite3_open@@$$J0YAHPBDPAPAUsqlite3@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1

How can I solve it? I should say that in Microsoft Visual Studio 2013, I have disabled pre-compiled headers, added a directory for my SQL.sql in Linker->additional directories, also added my headers and cpp files to aditional # include directories.

You will need to include the source file(s) that came with sqlite3 in your project. (Or, you could create a library that you would include with your project, but that's a slightly more complex answer.)

Anyway, yea, you probably have a file called "sqlite.c" -- just include that with your project so that it compiles as well. You may still have some other errors/warnings to resolve; however, I think that will take care of the unresolved externals.

If you have .lib or .dll files instead of actual source, then you'll just need to include those in your project similarly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM